【发布时间】:2016-09-27 11:06:11
【问题描述】:
我有这样的数据框:
month items
0 1962-01-01 589
1 1962-02-01 561
2 1962-03-01 640
3 1962-04-01 656
4 1962-05-01 723
我需要从此数据框中获取年份或月份并创建数组,但我不知道该怎么做。
预期结果:
years = [1962, 1962, 1962....]
monthes = [1, 2, 3, 4, 5.....]
你能帮帮我吗?
【问题讨论】:
-
抱歉这是
pandas?如果月份列是 dtype datetime 那么你可以只做years = df['month'].dt.year.tolist()和months = df['month'].dt.month.tolist()
标签: python python-2.7 pandas dataframe