熊猫数据框按年份绘制。需要代码来生成附件中的图像

Panda Data frame plot by year. Need code to generate the image like attached

我在 csv 文件中有一个数据,格式如下,我不确定如何安排这些数据以获得下面附加的图像

creation_time   physical_device_type
---------------   --------------------
7/25/2018 14:53   email
7/26/2018 14:53   printer
7/26/2017 14:53   email 
7/24/2017 14:53   printer
7/23/2017 14:53   email
7/22/2019 14:53   email
7/22/2019 14:53   fax
7/22/2019 14:53   fax

我想得到下面的图表,

Y 轴应显示计数,X 轴应显示年份

df = pd.read_csv('C:/test/test.csv');

先给read_csv for datetime column, then use crosstab for count and last plot加上parse_dates参数:

df = pd.read_csv('C:/test/test.csv', parse_dates=['creation_time'])

df1 = pd.crosstab(df['creation_time'].dt.year, df['physical_device_type'])
print (df1)
physical_device_type  email  fax  printer
creation_time                            
2017                      2    0        1
2018                      1    0        1
2019                      1    2        0

df1.plot()