简体   繁体   中英

Issue with Seaborn, not showing the values for Y axis in countplot

I have the following dataframe ( ordered_recurrent_df ) which I wish to plot in Seaborn's countplot:

ordered_recurrent_df :

Month   Card
January     4
February    7
March      11
April      32
May        96
June      704

When I try plotting it using countplot, I get the following:

sns.countplot(data = ordered_recurrent_df, x = ordered_recurrent_df.index)

在此处输入图像描述

The same outcome occurs when I try transposing it, it seems to me is not taking into account the values from the " Card " column. Like if it only recognizes the values as labels, but that's it.

Any help is appreciated Thanks in advance

barplot should work in your case:

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())

NB I did set an index because in your countplot example you also used the month index.

在此处输入图像描述

countplot can be used when your data looks like:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM