[英]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.