Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90082

Re: Writing list of dictionaries to CSV

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'feedback.': 0.04; 'puts': 0.07; 'formatting': 0.09; 'literal': 0.09; 'prevents': 0.09; 'spec': 0.09; 'to)': 0.09; 'accepting': 0.14; 'posted': 0.15; '(there': 0.16; '-tkc': 0.16; 'as-is': 0.16; 'columns': 0.16; 'csv': 0.16; 'editor,': 0.16; 'formatting.': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'imports': 0.16; 'itself,': 0.16; 'preserve': 0.16; 'received:10.21': 0.16; 'subject:CSV': 0.16; 'subject:Writing': 0.16; 'subject:dictionaries': 0.16; 'wizard,': 0.16; 'wrote:': 0.18; 'value.': 0.19; 'import': 0.22; 'specify': 0.24; 'file.': 0.24; 'excel': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; "doesn't": 0.30; 'subject:list': 0.30; '(which': 0.31; '-0700,': 0.31; 'cells': 0.31; 'values.': 0.31; 'file': 0.32; 'text': 0.33; 'problem': 0.35; 'problem.': 0.35; 'but': 0.35; 'dates': 0.36; 'in.': 0.36; 'charset:us-ascii': 0.36; 'thanks': 0.36; 'wrong': 0.37; 'received:10': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'first': 0.61; 'such': 0.63; 'taking': 0.65; 'export': 0.74; '2015': 0.84
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-MC-Relay Neutral
X-MailChannels-SenderId wwwh|x-authuser|tim@thechases.com
X-MailChannels-Auth-Id wwwh
X-MC-Loop-Signature 1430961682325:842411606
X-MC-Ingress-Time 1430961682325
Date Wed, 6 May 2015 20:22:05 -0500
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: Writing list of dictionaries to CSV
In-Reply-To <mie898$meu$2@dont-email.me>
References <5bd0afb3-d2d4-469f-be39-5869f01adc92@googlegroups.com> <072badd6-0542-468a-99bd-cc3a4ffc7156@googlegroups.com> <mie898$meu$2@dont-email.me>
X-Mailer Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AuthUser tim@thechases.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.196.1430963175.12865.python-list@python.org> (permalink)
Lines 36
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1430963175 news.xs4all.nl 2860 [2001:888:2000:d::a6]:55269
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:90082

Show key headers only | View raw


On 2015-05-06 23:31, Denis McMahon wrote:
> On Tue, 05 May 2015 22:32:28 -0700, Kashif Rana wrote:
> > thanks for the feedback. I think its problem with excel itself,
> > showing wrong value. Because when I opened the csv file in text
> > editor, I can see correct value but opening in excel showing
> > wrong value. What I can do to see correct in excel as well.
> 
> You need to format your CSV date into a date format that Excel 
> understands when it imports it.

That's part of the problem.  Excel is taking the OP's literal values
and interpreting them as dates (and formatting them in the way Excel
wants to) rather than accepting them as literal values.

As ChrisA posted earlier, you have to use Excel's Import
functionality (there are several ways to get this wizard, but not all
ways of opening a .csv trigger the wizard), then specify those
particular columns as "Text" rather than "General" (which
auto-detects as a Date).  This prevents Excel from overthinking the
problem, allowing Excel to import the text as-is like the OP wants.

> First thing to try would be to export some dates from excel as CSV
> and see what format excel puts them in.
> 
> The see if excel recognises them as dates when you re-import the
> same file.

If you create the formatting on such cells the way that the OP wants
them, then export, then re-import, Excel still mangles them since
the CSV spec doesn't preserve formatting.

-tkc



Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Writing list of dictionaries to CSV Kashif Rana <kashifrana84@gmail.com> - 2015-05-05 10:09 -0700
  Re: Writing list of dictionaries to CSV MRAB <python@mrabarnett.plus.com> - 2015-05-05 19:11 +0100
  Re: Writing list of dictionaries to CSV Skip Montanaro <skip.montanaro@gmail.com> - 2015-05-05 13:25 -0500
  Re: Writing list of dictionaries to CSV Cecil Westerhof <Cecil@decebal.nl> - 2015-05-05 20:44 +0200
  Re: Writing list of dictionaries to CSV Matthew Ruffalo <mmr15@case.edu> - 2015-05-05 15:43 -0400
  Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-05 12:34 -0500
  Re: Writing list of dictionaries to CSV Kashif Rana <kashifrana84@gmail.com> - 2015-05-05 22:32 -0700
    Re: Writing list of dictionaries to CSV Chris Angelico <rosuav@gmail.com> - 2015-05-06 16:34 +1000
    Re: Writing list of dictionaries to CSV Cecil Westerhof <Cecil@decebal.nl> - 2015-05-06 08:50 +0200
    Re: Writing list of dictionaries to CSV Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-05-06 09:14 -0400
    Re: Writing list of dictionaries to CSV MRAB <python@mrabarnett.plus.com> - 2015-05-06 19:08 +0100
    Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-06 13:22 -0500
    Re: Writing list of dictionaries to CSV Ian Kelly <ian.g.kelly@gmail.com> - 2015-05-06 12:27 -0600
    Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-06 13:37 -0500
    Re: Writing list of dictionaries to CSV Denis McMahon <denismfmcmahon@gmail.com> - 2015-05-06 23:31 +0000
      Re: Writing list of dictionaries to CSV Tim Chase <python.list@tim.thechases.com> - 2015-05-06 20:22 -0500
      Re: Writing list of dictionaries to CSV Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2015-05-07 01:55 +0000
      Re: Writing list of dictionaries to CSV [correction] Tim Chase <python.list@tim.thechases.com> - 2015-05-06 20:52 -0500

csiph-web