2

I would like to create a Bar chart from a pandas df

The source file is an excel file with column headers: ‘Jan’, ‘Feb’,’Mar’...

The rows contain just values

When I created the df in pandas I then transposed the df and used df.plot()

However, I could not get any axis labels.

Any advice would be good

df1=read_excel(‘filename’)

df1 = df1.T

df1 = df1.sum(axis=‘columns’)

df1.plot()

The output should be a column name followed by the sum of all corresponding values in each column including a visual Bar chart.

Thanks a lot!

1
  • 1
    Use matplotlib with data from your DataFrame. Commented Sep 5, 2019 at 16:46

1 Answer 1

2

I tried to reproduce the case, but it works with me using the following code :

data5.txt :

Jan Feb Mar
1   2   3
4   5   6

Then :

df1 = pd.read_csv('data/data5.txt', sep='\t')

df1 = df1.T
df1 = df1.sum(axis="columns")
ax = df1.plot(kind='bar')
ax.set_xlabel("Months")
ax.set_ylabel("Values")
ax.set_title("Title")

Result :

enter image description here

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

1 Comment

Thank you J.K - is it possible to add a graph total and axis labels? For instance ‘months’ / ‘values’. Also, is the method I used the best way to do it?

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.