df我想用Python打印一个时间序列,其中我的x轴具有存储在变量中且类型为STRING
的年份。我的y轴应打印主要类型“类别=毒品麻醉品I am expecting a graph like this
primary_type_categories Date1
Drug/Narcotic Violation 05-03-16 21:00
Serious Offenses 05-03-16 21:30
Violent Crimes 05-03-16 18:30
Non-Criminal 05-03-16 22:00
Drug/Narcotic Violation 05-03-16 21:30
`
import matplotlib.pyplot as plt
a=(df.Date1.dt.year).apply(str) -> Date1 is in Datetime format
plt.rcParams['figure.figsize']=20,7
b=df['primary_type_categories'].unique().tolist()
c=b[0]
plt.plot((a.groupby(c).agg('count')), c= 'black', ls='--', marker='s', ms=5)
plt.xticks(list(range(0,10)),a, rotation ='vertical')
plt.show()