I have year data in a pandas dataframe as following:
0 06/09/1937
1 22/11/1972
and i would like to extract only the year data:
0 1937
1 1972
My code:
features["year"] = df["birth_date"].str.split('/',2)
features["year"] = features["year"][:2]
I got an error as:
ValueError: Can only tuple-index with a MultiIndex
Then I tried
features["year"] = [x[2] for x in features["year"]]
TypeError: 'float' object is not subscriptable
I use Python 3. Could you tell me the reasons for these two errors and how to correct them? Thanks in advance.