Python Pandas 箱线图的实现
2019-10-11 18:07
1516 查看
各国家用户消费分布
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()
以上就是本文的全部内容,希望对大家的学习有所帮助
您可能感兴趣的文章:
相关文章推荐
- python pandas实现excel转为html格式的方法
- Python+pandas实现时间序列数据扩展案例一则
- python实现在pandas.DataFrame添加一行
- python中pandas模块实现SQL Server中的select
- python pandas 时间日期的处理实现
- Python3 -- 通过pandas实现快速创建java实体代码模板
- python pandas 实现SQl的count(*),count(distinct **)
- python pandas实现excel转为html格式
- python numpy和pandas包实现归一化和标准化
- Python pandas实现excel工作表合并功能详解
- 【Python】pandas实现row_number() over()函数
- Python pandas 实现图论算法 使用堆加速prim算法 dijkstra floyd
- python 用pandas,实现贝叶斯分类
- Python pandas DataFrame操作的实现代码
- Python使用matplotlib和pandas实现的画图操作【经典示例】
- python中pandas模块(merge方法)实现SQL Server中的表关联join
- 数据预处理(2) ——数据变换与数据离散化 使用python(sklearn,pandas,numpy)实现
- 数据预处理(1) ——数据清洗 使用python(sklearn,pandas,numpy)实现
- Python实现从SQL型数据库读写dataframe型数据的方法【基于pandas】
- 在Python环境下实现pandas的DataFrame与R中的DataFrame的相互转化方法