Grouped Bar graph Pandas

前端 未结 2 1614
忘掉有多难
忘掉有多难 2020-12-03 14:08

I have a table in a pandas DataFrame named df:

+--- -----+------------+-------------+----------+------------+-----------+
|avg_view         


        
相关标签:
2条回答
  • 2020-12-03 14:57

    You should not have to modify your dataframe just to plot it in a certain way right ?

    Use seaborn !

    import seaborn as sns
    
    
    sns.catplot(x = "x",       # x variable name
                y = "y",       # y variable name
                hue = "type",  # group variable name
                data = df,     # dataframe to plot
                kind = "bar")
    

    source

    0 讨论(0)
  • 2020-12-03 15:11

    Using pandas:

    import pandas as pd
    
    groups = [[23,135,3], [123,500,1]]
    group_labels = ['views', 'orders']
    
    # Convert data to pandas DataFrame.
    df = pd.DataFrame(groups, index=group_labels).T
    
    # Plot.
    pd.concat(
        [df.mean().rename('average'), df.min().rename('min'), 
         df.max().rename('max')],
        axis=1).plot.bar()
    

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