Pandas.read_csv date format

It is flagging an error. However, what I'm planning to do is to take the DateDpt and DateAr and look the range between them i.e DatePpt – DateAr. So that I can loop through the difference in dates and find other dates that fall between them considering maximum difference and place of Arrival and departure.

import datetime
import pandas.io.data
from pandas_datareader import data, wb
import csv
import time

df = pd.read_csv('data.csv')
df.DateDpt = pd.to_datetime(df.DateDpt, format='%y-%m-%d')
df.DateAr = pd.to_datetime(df.DateAr, format='%y-%m-%d')
print df

Data:

ID     ArCityArCountry      DptCityDptCountry   DateDpt     DateAr
1922   ParisFrance          NewYorkUnitedState  2008-03-10  2001-02-02
1002   LosAngelesUS         CaliforniaUS        2008-03-10  2008-12-01
1901   ParisFrance          LagosNigeria        2001-03-05  2001-02-02
1922   ParisFrance          NewYorkUSt          2011-02-03  2008-12-01
1002   ParisFrance          CaliforniaUS        2003-03-04  2002-03-04
1099   ParisFrance          BeijingChina        2011-02-03  2009-02-04
1901   LosAngelesUS         ParisFrance         2001-03-05  2001-02-02

Error:

ValueError: time data '2008-03-10' does not match format '%y-%m-%d' (match)

Answers


The lowercase y in the format string means that it's looking for the "Year without century as a zero-padded decimal number" (from datetime docs). Use the capital Y for the year with century.


Year with century is capital Y. So your format should be %Y-%m-%d.


You might find this cheat sheet handy for future reference: http://strftime.org/


Need Your Help

Performance Counter Category Names? (C#)

c# process msdn performancecounter

I'm trying to program in a performance counter into my C# application that launches another process and checks the processor usage of that launched process. As I understand it, the performance coun...

prevent multiple inheritance in C++

c++ inheritance multiple-inheritance

Recently I have attended one C++ technical interview: during that interviewer asked me one question which I was not able to answer: Even I tried on internet and some forums however unable to get the