我正在使用Google colab在python中使用plotly生成图形和图表。我有697000行数据存储在我正在分析的csv文件中。我正在使用下面的代码来生成条形图,它工作得很好。
fig = px.bar(df, x='IP', y="Epid_ID")
fig.update_traces(marker=dict(line=dict(width=3,color='blue')))
fig.show()现在,我想要一个显示累积数据的图表。下面是我的数据集的一个示例。
IP Epid_ID
05/08/2021 COV-NEP-PR4-LAM-21-01936
05/08/2021 COV-NEP-PR4-LAM-21-01937
06/08/2021 COV-NEP-PR4-LAM-21-01938
06/08/2021 COV-NEP-PR4-LAM-21-01939
07/08/2021 COV-NEP-PR4-LAM-21-01940我的预期输出是一个显示累积数据的条形图。当前输出:

预期输出

我尝试使用下面的链接来使用cumsum。https://www.codegrepper.com/code-examples/python/cumulative+chart+python+plotly
并尝试使用以下代码将日期变量保持为x。
x = df['IP']
y = df['Epid_ID']
cumsum = np.cumsum(x)但是,当我使用此代码时,我的运行时会崩溃。请帮帮我!
发布于 2021-08-07 11:52:56
构建直方图将为您提供预期的输出,因为它将数据分布在范围内。
试着使用这个
import plotly.express as px
import plotly.graph_objects as go
df = px.data.iris()
fig = go.Figure(data=[go.Histogram(y=df['sepal_width'], cumulative_enabled=True)])
fig.show()发布于 2021-08-07 11:35:42
所以我解释说你想要一个按计数升序排序的输出?您是否尝试使用df['Epid_ID'].sort("Epid_ID",ascending=False)对DataFrame或SubDataFrame进行排序。您还可以尝试在使用.count()之前聚合DataFrame。
df.groupBy("salutation").count().sort("count",ascending=False).show()
+------------+------+
| salutation| count|
+------------+------+
|not reported| 255|
| Company| 321|
| Family| 1467|
| Mr| 12012|
| Mrs|382567|
+------------+------+https://stackoverflow.com/questions/68691962
复制相似问题