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??
Errors:


You will need to use need the capital Y, not y
df["month"]=pd.to_datetime(df['date'],format="%Y-%m-%d").dt.month_name()
df.set_index('date', inplace=True)
Output:
new
month
2022-02-01 February
2022-09-10 September
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With