简体   繁体   中英

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!

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 :

在此处输入图片说明

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