我一直在尝试运行下面的代码。
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()
但是我收到错误:
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.
不知道如何解决。有人可以帮忙吗?
看起来您的索引只有年份值。你可以用它。
df_tracks.index=pd.to_datetime(df_tracks.index, format='%Y')