Plot a histogram using the index as x-axis labels

前端 未结 2 630
攒了一身酷
攒了一身酷 2020-12-19 07:21

I have the following dataframe in python

  Sex  Survived
0  female  0.742038
1    male  0.188908

i would like to plot a histogram, where ma

相关标签:
2条回答
  • 2020-12-19 07:40

    You don't want to plot a histogram, as your data is already histogrammed. Instead you want to plot a simple bar plot.

    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()
    

    0 讨论(0)
  • 2020-12-19 07:56

    In my opinion you need DataFrame.plot.bar:

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

    because histogram plot distribution of numerical data.

    0 讨论(0)
提交回复
热议问题