Мне кажется, у вас проблема с pandas
, а не с plotly
. Если вы ищете ежедневные смерти по континентам, вам следует использовать groupby.
Упорядочить данные
import pandas as pd
import plotly.express as px
import plotly.graph_objs as go
df = pd.read_csv("https://opendata.ecdc.europa.eu/covid19/casedistribution/csv")
# better to have data as datetime
df["dateRep"] = df["dateRep"].astype("M8")
# the previous is equivalent to
# df["dateRep"] = pd.to_datetime(df["dateRep"])
# now you want to look for the daily deaths
# for every continent
grp = df.groupby(["continentExp","dateRep"])["deaths"]\
.sum().reset_index()
используя plotly.express
fig = px.line(grp,
x="dateRep",
y="deaths",
color="continentExp",
labels={"deaths":"Tote",
"dateRep":"Datum"})
fig.update_layout(title="Covid-19 Dashboard",
title_x=0.5)
Using plotly.graph_objs
fig = go.Figure()
continents = grp["continentExp"].unique()
for continent in continents:
ts = grp[grp["continentExp"]==continent]
fig.add_trace(
go.Scatter(x=ts["dateRep"],
y=ts["deaths"],
name=continent))
fig.update_layout(title="Covid-19 Dashboard",
title_x=0.5,
xaxis={"title" : "Datum"},
yaxis={"title" : "Tote"})
введите описание изображения здесь