user28345
user28345

Reputation: 21

Bar chart from Pandas Dataframe

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!

Upvotes: 2

Views: 170

Answers (1)

O.O
O.O

Reputation: 1298

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

Upvotes: 2

Related Questions