I can't get month and day from date in the correct format.
I'm using both pd.DatetimeIndex(df['date1']).month
and pd.to_datetime(parity['date1']).dt.month
but it still retrieves day as month and only if value is larger than 12 it considers it as day.
Thank you in advance
CodePudding user response:
Specify format of dates:
df['date1'] = pd.to_datetime(df['date1'], format='%d.%m.%Y').dt.month
Or set parameter dayfirst=True
:
df['date1'] = pd.to_datetime(df['date1'], dayfirst=True).dt.month