[英]Issue with Seaborn, not showing the values for Y axis in countplot
我有以下 dataframe ( ordered_recurrent_df
) 我希望在 Seaborn 的计数图中 plot :
ordered_recurrent_df
:
Month Card
January 4
February 7
March 11
April 32
May 96
June 704
当我尝试使用 countplot 绘制它时,我得到以下信息:
sns.countplot(data = ordered_recurrent_df, x = ordered_recurrent_df.index)
当我尝试转置它时会发生相同的结果,在我看来,它似乎没有考虑“卡片”列中的值。 就像它只将值识别为标签一样,仅此而已。
任何帮助表示赞赏提前谢谢
barplot
应该适用于您的情况:
ordered_recurrent_df = pd.DataFrame(
{'Month':['January','February','March', 'April', 'May', 'June'],
'Card':[4, 7, 11, 32, 96, 704]
}
).set_index('Month')
sns.barplot(x='Month', y='Card', data=ordered_recurrent_df.reset_index())
注意我确实设置了一个索引,因为在您的countplot
示例中您还使用了month
索引。
当您的数据如下所示时,可以使用countplot
:
ordered_recurrent_df = pd.DataFrame(
{'Month':['January','February','March', 'April', 'May', 'June'],
'Card':[range(4), range(7), range(11), range(32), range(96), range(704)]
}
).set_index('Month').explode('Card')
sns.countplot(data = ordered_recurrent_df, x = ordered_recurrent_df.index)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.