gpt4 book ai didi

python - 如何使用带有日期的 plotly graph_objects scatter

转载 作者:行者123 更新时间:2023-12-04 10:21:58 29 4
gpt4 key购买 nike

从我复制到自己服务器的已知公共(public)数据集开始。

数据集在这里:https://www.kaggle.com/imdevskp/corona-virus-report/download

import pandas as pd
#df = pd.read_csv("http://g0mesp1res.dynip.sapo.pt/covid_19_clean_complete.csv", index_col=4, parse_dates=True)
df = pd.read_csv("http://g0mesp1res.dynip.sapo.pt/covid_19_clean_complete.csv")
df=df.drop(labels=None, axis=0, index=None, columns=['Province','Lat','Long'], level=None, inplace=False, errors='raise')
#print(df.head())
df['Date']=pd.to_datetime(df['Date'])
#print(df.head())
list_countries = ['Portugal','Brazil','Spain','Italy','Korea, South','Japan']
df= df[df['Country'].isin(list_countries)]
df_pt = df[df.Country == 'Portugal']
df_es = df[df.Country == 'Spain']
df_it = df[df.Country == 'Italy']
print(df_pt.head())
print(df_pt.tail())

我得到了我所期望的
       Country       Date  Confirmed  Deaths  Recovered
59 Portugal 2020-01-22 0 0 0
345 Portugal 2020-01-23 0 0 0
631 Portugal 2020-01-24 0 0 0
917 Portugal 2020-01-25 0 0 0
1203 Portugal 2020-01-26 0 0 0
Country Date Confirmed Deaths Recovered
15503 Portugal 2020-03-16 331 0 3
15789 Portugal 2020-03-17 448 1 3
16075 Portugal 2020-03-18 448 2 3
16361 Portugal 2020-03-19 785 3 3
16647 Portugal 2020-03-20 1020 6 5

但是,在绘图时,似乎所有数据都是一月份的!
import plotly.graph_objects as go
fig = go.Figure( go.Scatter(x=df.Date, y=df_pt.Confirmed, name='Portugal'))
fig.show()

绘制输出图:

enter image description here

什么不见​​了?

最佳答案

x=df.Date 更改 x 轴至x = df_pt.Date :

import plotly.graph_objects as go

fig = go.Figure(go.Scatter(x = df_pt.Date,
y = df_pt.Confirmed,
name='Portugal'))
fig.show()

你得到:

enter image description here

关于python - 如何使用带有日期的 plotly graph_objects scatter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60812566/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com