date

Mark Lawrence breamoreboy at yahoo.co.uk
Mon Mar 2 11:41:52 EST 2015


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




More information about the Python-list mailing list