来自数据框的多线图

发布于 2025-02-03 03:40:13 字数 564 浏览 1 评论 0 原文

从数据框架中,我需要按月绘制事件计数,以了解在给定一个月内更有可能发生哪些事件。我不知道如何使用列计数。

df["MONTH"]= pd.to_datetime(df["BEGIN_DATE_TIME"], format = "%m/%d/%Y").dt.month
montly_events =df.groupby(["EVENT_TYPE", "MONTH"]).size().astype(int)
montly_events2 = montly_events.to_frame(name = "Count").reset_index()

plt.figure(figsize =(15,3))
sns.lineplot(x="MONTH", y="EVENT_TYPE", palette="ch:.25", data=df)

from a dataframe I need to plot by month the count of events to know which ones are more likely to happen in a given month. I don know how to use the column Count.

df["MONTH"]= pd.to_datetime(df["BEGIN_DATE_TIME"], format = "%m/%d/%Y").dt.month
montly_events =df.groupby(["EVENT_TYPE", "MONTH"]).size().astype(int)
montly_events2 = montly_events.to_frame(name = "Count").reset_index()

plt.figure(figsize =(15,3))
sns.lineplot(x="MONTH", y="EVENT_TYPE", palette="ch:.25", data=df)

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

彩扇题诗 2025-02-10 03:40:13

iiuc,计数是您的DF中的另一列,尝试将其作为“ y”,您在此包含的截图作为屏幕截图

尝试

sns.lineplot(x="MONTH", y="count", palette="ch:.25", data=df)

IIUC, count is another column in your df, try to make that as a 'y', the one that you have included here as screenshot

Try

sns.lineplot(x="MONTH", y="count", palette="ch:.25", data=df)
梦回梦里 2025-02-10 03:40:13

这是我使用一个Barplot发现的解决方案:

g = sns.FacetGrid(montly_ev2, row="EVENT_TYPE", hue="MONTH",palette="Set3", height=4, aspect=2)

g.map(sns.barplot, 'MONTH', 'Count', order=hours)

This was the solution I found using a barplot:

g = sns.FacetGrid(montly_ev2, row="EVENT_TYPE", hue="MONTH",palette="Set3", height=4, aspect=2)

g.map(sns.barplot, 'MONTH', 'Count', order=hours)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文