在熊猫系列日期中,我可以使用哪个熊猫系列方法来匹配特定的年份?
import pandas as pd
date_series = pd.Series(["1 jan 2022", "2021-01-31", "19 dec 2016"])
print(date_series.**someMethod**("2021"))
我想要的输出类似于:
FALSE
TRUE
FALSE
import pandas as pd
date_series = pd.Series(["1 jan 2022", "2021-01-31", "19 dec 2016"])
date_series = pd.to_datetime(date_series)
date_series.dt.year == 2021
>>
0 False
1 True
2 False
dtype: bool