绘制时间序列d时出现值错误

2024-09-26 18:15:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为时间序列数据绘制条形图/计数图:

avg_curr1 = df[df['name'] == 'name1'].groupby(["Week of the Month", "Month"]).count()
print(avg_curr1)

输出:

Week of the Month  Month  col1  col2  col3  col3  col4
1                  10     1055  1055  1055  1055  1055
                   11     842   842   842   842   842
                   12     789   789   789   789   789
2                  10     668   668   668   668   668
                   11     846   846   846   846   846
                   12     802   802   802   802   802
3                  10     752   752   752   752   752
                   11     684   684   684   684   684
                   12     134   134   134   134   134
4                  10     447   447   447   447   447
                   11     462   462   462   462   462
                   12     386   386   386   386   386
5                  9      58    58    58    58    58
                   10     265   265   265   265   265
                   11     140   140   140   140   140
                   12     230                     

所以基本上,这些是过去三个月的数值,被分为每个星期。你知道吗

然后我试着:

sns.set(style="darkgrid")
ax = sns.countplot(x="avg_curr1", data=avg_curr1, hue = 'Month')

引发了一个值错误。你知道吗

我是否错误地聚合了数据?提前感谢您的建议!你知道吗


Tags: ofthe数据df错误时间绘制序列
2条回答

修改图形以获取输出:

avg_curr1 = df[df['name'] == 'name1'].groupby(["Week of the Month", "Month"]).count().reset_index().sort_values(by = "name",ascending=False)
data = pd.concat([avg_curr1], axis=0)
ax = sns.pointplot("Week of the Month", "name", data = data, hue = "Month", markers = "H")

如果您想分析每月每周的计数,那么应该使用barplot而不是countplot。你知道吗

import pandas as pd
import seaborn as sns
avg_curr1=pd.read_excel(INPATH)
avg_curr1=avg_curr1.ffill(axis = 0)
sns.set(style="darkgrid")
s=sns.barplot(x='Week of the Month',y='col1',data=avg_curr1, hue ='Month')

enter image description here

相关问题 更多 >

    热门问题