2

Consider the following dataframe, this is what it looks like on jupyter notebook:

in(1): df

out(1):

months          0   1   3   6   12

        name                    
------------------------------------
     janedoe    1.0 3.0 3.0 2.0 1.0
     johndoe    3.0 2.0 3.0 1.0 1.0
     tfbundy    1.0 3.0 3.0 3.0 3.0
     someone    1.0 2.0 3.0 4.0 4.0
     another    1.0 2.0 2.0 3.0 2.0
         ...    ... ... ... ... ...

etc 700 rows. I wish to create a bar chart with stdev error bars where on the y-axis is the mean score (1.0, 3.0 etc) of each month column and on the x-axis are the months (0,1,3,6,12). How do I do this?

Thank you.

1 Answer 1

2

The easiest way would be through seaborn.barplot, as it creates error bars and other nice stuff.

First, melt the DataFrame:

m = pd.melt(df).rename(columns={'variable': 'month'})

This will create a DataFrame with two columns: month and value. Now plot it:

import seaborn as sns

sns.barplot(x='month', y='value', data=m)

For the data in your sample, it will look like this:

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much. This solved my problem. Didn't occur to me to melt the dataframe.

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.