Making a clustered bar chart, Pandas

后端 未结 3 1577
悲哀的现实
悲哀的现实 2021-01-22 11:35

I have a little pandas dataframe that looks like this:

    Word   Percentage1  Percentage2
1   drink   18.166654   29.014272
2   cherry  13.498262   12.802642
3          


        
相关标签:
3条回答
  • 2021-01-22 12:05

    You can choose stacked bar graph:

    # Given
    df = pd.DataFrame({'word':['Alpha', 'Bravo', 'Charlie'],
                      'Percentage 1':[10, 3, 0],
                      'Percentage 2': [5, 6, 4]})
    
    df.set_index('word').plot(kind='barh', stacked=True)
    

    0 讨论(0)
  • 2021-01-22 12:17

    try this,

    df.set_index('Word').plot(kind='bar')
    

    O/P

    If you don't want to perform chart for all the values columns in df use this. Just setting index act as X and rest of all the columns act as y

    Input:

         Word  Percentage1  Percentage2  Percentage3  Percentage4
    0   drink    18.166654    29.014272     7.105845    29.014272
    1  cherry    13.498262    12.802642     4.715009    12.802642
    2   berry     9.810123     6.775552     6.097997     3.408988
    3    plum     7.964429     7.105845    12.802642    19.620618
    4   crisp     7.892941     4.715009     6.775552    35.832248
    

    O/P

    0 讨论(0)
  • 2021-01-22 12:27

    If I understand you correctly, you can do in this way:

    df.plot(x="Word", y=["Percentage1", "Percentage2"], kind="bar")
    

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