Hi already referred to this post but I could not get through my issue. I have a column in my CSV which is string and the sample values are below (note that the month
and year
positioning are sometimes reversed). What format do I need to set in my to_datetime
? I tried all the below approaches
df = pd.read_csv("filename.csv") #Imagine there is a Month column
#[1] df["Month"] = pd.to_datetime(df["Month"])
#[2] df["Month"] = pd.to_datetime(df["Month"], format="%m/%d/%Y")
[Month]
Mar-97
Apr-97
May-97
Jun-97
Nov-00
Dec-00
1-Jan
1-Feb
1-Mar
1-Apr
I get the error
ValueError: day is out of range for month
for [1] and I get
ValueError: time data 'Mar-97' does not match format '%m/%d/%Y' (match)
for [2]. I tried to remove the %d
too but no luck. Could you please point me what is going wrong here.