I have a column in my dataframe, df['Month']
, that has month names: January, February, etc.
I want to convert these to month numbers: 1, 2, etc.
In my Pandas, df['Month_Num'] = list(cal.month_abbr).index(df['Month'])
throws error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Pandas:
import pandas as pd
import calendar as cal
df['Day'] = 1
# convert 'January' to 1
df['Month_Num'] = list(cal.month_abbr).index(df['Month'])
df['date_tw'] = ''
# Create date_time based on format `mm/dd/yy`:
df['date_tw'] = pd.to_datetime(df[['Month_Num', 'Day', 'Year']])
result_df = df
Why is this occurring? The only data I could find on it was from here related to comparison operators, which mine is not using.