python 3.x - take the year from date type in a pandas dataframe column -


i have year data in pandas dataframe following:

0     06/09/1937  1     22/11/1972 

and extract year data:

0     1937  1     1972 

my code:

features["year"] = df["birth_date"].str.split('/',2) features["year"] = features["year"][:2] 

i got error as:

valueerror: can tuple-index multiindex

then tried

features["year"] = [x[2] x in features["year"]] 

typeerror: 'float' object not subscriptable

i use python 3. tell me reasons these 2 errors , how correct them? in advance.

you need:

features["year"] = df["birth_date"].str.split('/',2) features["year"] = features["year"].str[:2] 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -