Ad

Python Error_time Data Does Not Match Format

- 1 answer

I am working with a CSV file which contain daily weather data for different month, i am trying to monthly aggregating the daily data using below script,

df.Timestamp = pd.to_datetime(df.Datetime,format='%d-%m-%y %H:%M') 
data.index = data.Timestamp
df = df.resample('W').mean()

I am getting the following error,

Input file description

time data '01-01-2000 00:00' does not match format '%d-%m-%y %H:%M' (match)

How to resolve it.

Ad

Answer

Use %Y for match YYYY, if use %y it match YY format of year:

df.Timestamp = pd.to_datetime(df.Datetime,format='%d-%m-%Y %H:%M') 

Then create DatetimeIndex:

df = df.set_index('Timestamp').resample('W').mean()
Ad
source: stackoverflow.com
Ad