[英]plot matplotlib aggregated data python
我需要聚合數據圖
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.
我應該怎么做才能運行這個情節? 數據集鏈接
列名包含一個前導空格(通過檢查basic_data.dtypes
可以很容易地看到)。 通過在讀取basic_data
后立即添加以下行來解決此問題:
basic_data.columns = [s.strip() for s in basic_data.columns]
此外,您的 x 變量應該是groupby-sum
之后的索引,而不是Date_reported
列。 更正:
x = cum_daily_cases.index
該圖應按預期顯示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.