zoukankan      html  css  js  c++  java
  • Python Pandas 箱线图

    各国家用户消费分布

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    
    data = {
        'China': [1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2500],
        'America': [1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100],
        'Britain': [1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],
        "Russia": [800, 1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]
    }
    df = pd.DataFrame(data)
    
    # df.plot.box(title="Consumer spending in each country", vert=False)
    df.plot.box(title="Consumer spending in each country")
    
    plt.grid(linestyle="--", alpha=0.3)
    plt.show()
    

      

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    
    data = {
        'China': [1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2500],
        'America': [1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100],
        'Britain': [1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000],
        "Russia": [800, 1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900]
    }
    df = pd.DataFrame(data)
    
    from pandas.plotting import table
    
    fig, ax = plt.subplots(1, 1)
    
    table(ax, np.round(df.describe(), 2),
          loc='upper right',
          colWidths=[0.1, 0.1, 0.1, 0.1]
          )
    
    # df.plot.box(title="Consumer spending in each country", vert=False)
    df.plot.box(title="Consumer spending in each country",
                ax=ax,
                ylim=(750, 3000))
    
    plt.grid(linestyle="--", alpha=0.3)
    plt.show()
    

      

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    
    data = {"gender": [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
            'China': [1000, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2500],
            'America': [1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100]
            }
    df = pd.DataFrame(data)
    
    # df.boxplot(column=["China", "America"], by="gender",vert=False)
    df.boxplot(column=["China", "America"], by="gender")
    
    plt.grid(linestyle="--", alpha=0.3)
    plt.show()
    

      

  • 相关阅读:
    树套树+【UVALive】6709 Mosaic 二维线段树
    汇编实验1. 计算1+2+3+…+10,将结果显示在屏幕上。4
    Tinkoff Internship Warmup Round 2018 and Codeforces Round #475 (Div. 2) D. Destruction of a Tree
    HDU 4417 Super Mario主席树
    spoj+B
    2018-2019赛季多校联合新生训练赛第五场(2018/12/14)补题题解
    迷宫问题 POJ
    浅谈二分搜索与二分查找
    Moving Tables POJ
    Humidex POJ
  • 原文地址:https://www.cnblogs.com/wwxbi/p/9032248.html
Copyright © 2011-2022 走看看