Reputation: 1
Probably very simple, however I cannot find the right format for parsing dates in a dataframe.
Date to parse: Thu, Apr 1, 2021 (df name: df data, column name: Date )
My attempt:
date_p = pd.to_datetime(nba_data.Date, format = '%a%b%-m%Y')
I am aware that the '-' is according to the Error a bad directive in the format. However solely %m would according to my knowledge refer to 01 and not 1. Am I correct with that assumption.
Would be very thankful for any help.
Upvotes: 0
Views: 48
Reputation: 4648
It seems like no format indication is required, as pandas (v1.2.3 with python 3.8) already recognizes such format.
print(pd.to_datetime(df["Date"])
Out[185]:
0 2021-04-01
Name: Date, dtype: datetime64[ns]
df = pd.read_csv(io.StringIO("""
Date
Thu, Apr 1, 2021
"""), sep=r"\s{2,}", engine='python')
print(df)
Date
0 Thu, Apr 1, 2021
Upvotes: 1