# Convert to date format or specify date format , Be careful format The specified date format is the acquired date format
>>> ebola['date_dt']=pd.to_datetime(ebola['Date'],format='%m/%d/%Y')
>>> print(ebola.iloc[:5,:5])
Date Day Cases_Guinea Cases_Liberia Cases_SierraLeone
0 1/5/2015 289 2776.0 NaN 10030.0
1 1/4/2015 288 2775.0 NaN 9780.0
2 1/3/2015 287 2769.0 8166.0 9722.0
3 1/2/2015 286 NaN 8157.0 NaN
4 12/31/2014 284 2730.0 8115.0 9633.0
>>> ebola['date_dt']=pd.to_datetime(ebola['Date'],format='%d/%m/%Y')
# Due to the output above ebola The data shows that , The fifth row of data has 31, It cannot be used as a month , Therefore, the following error occurs
ValueError: time data '12/31/2014' does not match format '%d/%m/%Y' (match)
The character meaning specified when converting to date format
Symbol
meaning
%a Abbreviated name of the week %A The full name of the week %w Show weeks in numbers ,0 It's Sunday %d Every day of the month ( Two figures )%b The abbreviation of the month name %B The full form of the month name %m month ( Two digits )%y year ( Two digits )%Y year ( Four digit number )%H Hours ( Two digit number ,24 hourly )%I Hours ( Two digit number ,12 hourly )%pAM or PM%M minute ( Two digit number )%S second ( Two digit number )%f Microsecond %zUTC The offset ( +HHMM or -HHMM )%Z Time zone name %j Every day of the year ( Three digits )%U Weeks of the year ( Sunday is the first day )%W Weeks of the year ( Monday is the first day )%c Date and time represent %x The date means %X Time means %%% character %GISO 8601 year %uISO 8601 week %VISO 8601 week