探索性数据分析是否有一种方法可以在Python中绘制与其类别(另一列)相对应的子类别(列)?

2024-09-30 10:28:57 发布

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

例如,我有一个名为Category的专栏,在该专栏下我有家具、办公用品和技术。我想绘制另一个名为Sub Category的列,但在绘制时我遇到了一个问题。我想绘制子类别列,它的值与类别列平行,但我得到的是子类别列中所有值的单个绘图。 让我来描述一下:

superstore = pd.read_csv('SampleSuperstore.csv')
superstore.head()

this is returning the table

superstore.groupby(['Category', 'Sub-Category']).size()

when grouping by 'Category'

我试过这个代码来进行绘图

sns.catplot(x='Category', y='Profit', hue='Sub-Category', data=superstore, kind='bar', aspect=4)

This is the output, a categorical plot

我想分别绘制家具、办公用品和技术的子类别。 每个类别和相应子类别的单独绘图


Tags: csv绘图read绘制类别技术pdcategory

热门问题