AttributeError: 'Series' object has no attribute 'datetime'
对时间序列还不熟悉,请教了
1个回答
试试这个
import pandas as pd
data = {'birth':['2010/01/01', '2013/01/01']}
frame = pd.DataFrame(data)
frame['birth'] = pd.to_datetime(frame['birth'])
now_year = pd.to_datetime('today').year
frame['age'] = now_year - frame['birth'].apply(lambda x: x.year)