df["month"]=pd.to_datetime(df['date'],format="%y-%m-%d").dt.month_name()
df.set_index('date', inplace=True)
I used this code to extract month name from the date series in my CSV file. All the dates had a format of yyyy-mm-dd. So i used %y-%m-%d
to extract month name from the date. But I'm getting key error. Can u tell me where I made the mistake??
CodePudding user response:
Your format string is incorrect you need to use "%Y-%m-%d"
. %y
is for two digit years, %Y
is for four digit years.