Pandas: Bar-Plot with two bars and two y-axis

后端 未结 4 987
清酒与你
清酒与你 2020-11-30 23:21

I have a DataFrame looking like this:

     amount     price
age
A     40929   4066443
B     93904   9611272
C    188349  19360005
D    248438  24335536
E             


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 23:45

    You just need to write: df.plot( kind= 'bar', secondary_y= 'amount')

    import matplotlib.pyplot as plt
    import numpy as np
    import pandas as pd
    from io import StringIO
    s = StringIO("""     amount     price
    A     40929   4066443
    B     93904   9611272
    C    188349  19360005
    D    248438  24335536
    E    205622  18888604
    F    140173  12580900
    G     76243   6751731
    H     36859   3418329
    I     29304   2758928
    J     39768   3201269
    K     30350   2867059""")
    df = pd.read_csv(s, index_col=0, delimiter=' ', skipinitialspace=True)
    
    _ = df.plot( kind= 'bar' , secondary_y= 'amount' , rot= 0 )
    plt.show()
    

提交回复
热议问题