I have a data frame named 'train' which has number of variables. One such variable is 'industry'. The first 10 elements of column 'industry' are as follows:
train['industry'][:10]
0 Office supplies
1 Unknown
2 Misc services
3 Social services
4 Unknown
5 Manufacturing
6 Social services
7 Office supplies
8 Entertainment
9 Construction
Name: industry, dtype: object
I am trying to plot a bar chart using matplotlib.pyplot as plt library with industry type on x-axis and their frequency on y-axis. I am not really sure what to should be the value of 'height' argument?
plt.bar(train['industry'], height = )
Height is your frequency. Here's an example
Make array of length len(train.index)
Make your bar chart without the industry names - plt.bar(array, frequency)
. The frequency/height cannot be a string. It needs to be numerical. If it isn't, convert it using pd.to_numeric
Put industry names into an array
use set_xticklabels(industries)
to change the labels
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.