将两个箱图分组绘制两列

时间:2017-10-25 09:05:21

标签: python-3.x

import matplotlib.pyplot as plt 
import numpy as np 
import matplotlib as mpl 
import pandas as pd

filepath='E:/PROJECT ON DATA SCIENCE/boxplot/fee.csv';
X=pd.read_csv(filepath_or_buffer=filepath,index_col=0)

X.boxplot(by='stype', column='fee')
X.boxplot(by='pincode', column='fee')

1 个答案:

答案 0 :(得分:1)

如果您想通过stypepincode对X分组进行箱线图绘制,则可以使用

X.boxplot(column='fee', by=['stype', 'pincode'])

完整的代码应该是

import matplotlib.pyplot as plt 
import numpy as np 
import matplotlib as mpl 
import pandas as pd

filepath='E:/PROJECT ON DATA SCIENCE/boxplot/fee.csv';
X=pd.read_csv(filepath_or_buffer=filepath,index_col=0)

X.boxplot(column='fee', by=['stype', 'pincode'])