0

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 DatePptDateAr. 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)

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I have corrected the error. Please how do I go about the difference i.e. (DateDpt - DateAr) ? All I want to do is to check if any "ID" visit specific country, city the same period. for instance "1922" was at ParisFrance from NewYorkUnitedState between 2001-02-02 and 2008-03-10, is there anyone in ParisFrance on the list between 2001-02-02 to 2008-03-10
1

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/

5 Comments

Thanks! I have corrected the error. Please how do I go about the difference i.e. (DateDpt - DateAr) ? All I want to do is to check if any "ID" visit specific country, city the same period. for instance "1922" was at ParisFrance from NewYorkUnitedState between 2001-02-02 and 2008-03-10, is there anyone in ParisFrance on the list between 2001-02-02 to 2008-03-10
df[(df['date'] > '2001-02-02') & (df['date'] < '2008-03-10')]
Let's assume we don't the range but want to iterate through the csv (with values will don't)
@Payne you should consider asking another question. If this answered your original question, do accept it. :-)
Sorry, i have been trying to run comparison of date within the csv file without knowing what could be the highest value or lowest value and generate series of date between the lowest and the highest

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.