I have been trying to run the below code.
df_tracks.set_index('release_date' ,inplace=True) # inplace mutates the original df
df_tracks.index=pd.to_datetime(df_tracks.index)
df_tracks.head()
But I am getting error as:
ValueError: time data "1922" doesn't match format "%Y-%m-%d", at position 3. You might want to try:
- passing `format` if your strings have a consistent format;
- passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format;
- passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.
Not sure how to resolve it. Can anyone please help?
Looks like your index has only year values. So you should set format in your
pd.to_datetimewhich for your caseformat = "Y". So, you can use that.It will convert 1992 to 1992-01-01