Adjust the histogram using index, X axis designation

I have the following data frame in python

  Sex  Survived
0  female  0.742038
1    male  0.188908

I would like to build a histogram where the male and female are two values ​​along the x axis, and the y axis has corresponding values. Any idea how ?, I am new to matplotlib and pandas, so please help

+4
source share
2 answers

In my opinion, you need DataFrame.plot.bar:

df.plot.bar(x='Sex', y='Survived')

graph

because the histogramgraph is the distribution of numerical data.

+5
source

You do not want to plot a histogram since your data is already histogrammed. Instead, you want to build a simple schedule.

import io
import pandas as pd
import matplotlib.pyplot as plt

u = u"""Sex Survived
female 0.742038
male 0.188908"""

df = pd.read_csv(io.StringIO(u), delim_whitespace=True)

df.plot.bar(x="Sex", y="Survived")

plt.show()

enter image description here

+2
source

Source: https://habr.com/ru/post/1680015/


All Articles