1

how to use groupby function in the y-axis? the below code doesn't display what i expect, due to y = df.groupby('column1')['column2'].count()

import seaborn as sns
import pandas as pd

sns.set(style="whitegrid", color_codes=True)

sns.stripplot(x="column1", y = df.groupby('column1')['column2'].count(), data=df)
0

2 Answers 2

5

Seaborn just doesn't work that way. In seaborn, you specify the x and y columns as well as the data frame. Seaborn will do the aggregation itself.

import seaborn as sns
sns.striplot('column1', 'column2', data=df)

For the count, maybe what you need is countplot

sns.countplot('column1', data=df)

The equivalent pandas code is:

df.groupby('column1').size().plot(kind='bar')
Sign up to request clarification or add additional context in comments.

1 Comment

for grouping by, you can use parameter 'hue' within countplot
0

this code will create a count plot with horizontal bar equivalent and descending sorted values

fig,ax = plt.subplots(figsize=(10,16))
grouped=df.groupby('Age').size(). \
sort_values(ascending=False).plot(kind='barh',ax=ax)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.