简体   繁体   English

绘制matplotlib聚合数据python

[英]plot matplotlib aggregated data python

I need plot of aggregrated data我需要聚合数据图

import pandas as pd
basic_data= pd.read_csv('WHO-COVID-19-global-data _2.csv',parse_dates= ['Date_reported'] )
cum_daily_cases = basic_data.groupby('Date_reported')[['New_cases']].sum()

import pylab
x = cum_daily_cases['Date_reported']
y = cum_daily_cases['New_cases']
pylab.plot(x,y)
pylab.show()

Error: 'Date_reported'

Input: Date_reported, Country_code, Country, WHO_region, New_cases, Cumulative_cases, New_deaths, Cumulative_deaths 2020-01-03,AF,Afghanistan,EMRO,0,0,0,0

Output: the total quantity of "New cases" showed on the plot per day.

What should I do to run this plot?我应该怎么做才能运行这个情节? link to dataset数据集链接

The column names contain a leading space (can be easily seen by checking basic_data.dtypes ).列名包含一个前导空格(通过检查basic_data.dtypes可以很容易地看到)。 Fix that by adding the following line immediately after basic_data was read:通过在读取basic_data后立即添加以下行来解决此问题:

basic_data.columns = [s.strip() for s in basic_data.columns]

In addition, your x variable should be the index after groupby-sum , not a column Date_reported .此外,您的 x 变量应该是groupby-sum之后的索引,而不是Date_reported列。 Correction:更正:

x = cum_daily_cases.index

The plot should show as expected.该图应按预期显示。

伊格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM