How to plot histogram from two columns

Viewed 442

I have a csv file containing two columns. What I'd like to do is to plot a histogram based on these two columns.

My code is as follows:

data = pd.read_csv('data.csv')

My csv data is made like this:

Age     Blood Pressure
51           120
..           ...

I tried with plt.hist(data['Age'], bins=10) which only gives me an histogram based on the first column and its frequency, the same goes for the second column. Is there a way to plot an histogram which shows me "Ages" in the x-Axis and "Blood Pressure" in the y-Axis?

1 Answers

Maybe you could use a Bar chart

This code will do the job probably:

plt.bar(data['Age'], data['Blood Pressure'], align='center')
plt.xlabel('Age') 
plt.ylabel('Blood Pressure')
plt.title('Bar Chart')
plt.show()

More about Bar charts: https://pythonspot.com/matplotlib-bar-chart/

Related