<分区>
我有一个数据框 df_1
,其中有一列 year
,表示犯罪发生的年份。例如,df_1 是这样的:
location description Weapon Year
0 Howard Ave Auto theft Knife 2017
1 Craig Drive Burglary Gun 2014
2 King Ave Assault Hands 2017
我需要创建一个数据框,其中包含从 2012 年到 2017 年的犯罪事件数量。
crime_year = pd.DataFrame(df_1.year.value_counts(), columns=["Year", "AggregateCrime"])
crime_yearindex = crime_year.sort_index(axis = 0, ascending=True)
crime_yearindex
当我打印 crime_yearindex
时,我只得到列标题而不是数据本身。我可能做错了什么?