Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'string': 0.09; 'lawrence': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'yeah,': 0.09; 'python': 0.11; 'suggest': 0.14; 'language.': 0.14; 'background,': 0.16; 'csv': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'stdlib.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'file,': 0.19; '>>>': 0.22; 'import': 0.22; 'header:User-Agent:1': 0.23; 'cheers,': 0.24; "i've": 0.25; 'least': 0.26; 'header:X -Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'originally': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'file': 0.32; 'week.': 0.33; 'convert': 0.35; 'but': 0.35; "i'll": 0.36; 'url:org': 0.36; 'should': 0.36; 'being': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'read': 0.60; 'life,': 0.60; 'hope': 0.61; 'first': 0.61; 'complete': 0.62; 'such': 0.63; 'myself': 0.63; 'our': 0.64; 'telling': 0.64; 'charset:windows-1252': 0.65; 'day': 0.76; 'received:2': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: date Date: Mon, 02 Mar 2015 16:41:52 +0000 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-98-199-155.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.19 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1425314529 news.xs4all.nl 2942 [2001:888:2000:d::a6]:43205 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86760 On 02/03/2015 15:42, Fabien wrote: > On 02.03.2015 15:26, Mark Lawrence wrote: >>> >>> Have you tried Pandas? http://pandas.pydata.org/ >>> >>> If your csv file has no other problems, the following should do the >>> trick: >>> >>> import pandas as pd >>> df = pd.read_csv('file.csv', index_col=0, parse_dates= {"time" : [0]}) >>> >>> Cheers, >>> >>> Fabien >>> >> >> IMHO complete overkill. Give me the Steven D'Aprano solution any day of >> the week. > > Without knowing anything about the OP background, I still hope my > suggestion is a good one. Pandas is one of the best thing that happened > to me in my python life, I'm happy to at least suggest it. But yeah, if > you just want to read the csv and do no data crunching on it, pandas is > "overkill". > > Fabien I've used pandas myself and I'll admit to being very impressed. However the OP originally said 'I have a csv file, the first item on a line is the date in the format 2015-03-02 I try to get that as a date by date(row[0]), but it barfs, replying "Expecting an integer".' Without finding out exactly what the OP is trying to achieve, telling them to download a package such as pandas just to convert a string to a date is overkill when there's a solution in the stdlib. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence