python画流程图模块_在python中绘制框图而不对数据进行分组

1586010002-jmsa.png

I want to plot a box plot for a variable in a data frame xldata['yaxis_data'] according to 1,0 mapping stored in another array (one_zero_map).

I have a working code for this I am just not sure if this is the best way. Any help would be great.

Reason I am unsure is I am guessing there should be a direct way for boxplot to understand what I want if I input directly one_zero_map and xldata['yaxis_data'] without creating good_ones and bad_ones and then putting them in a list called final_list

%matplotlib inline

import matplotlib.pyplot as plt

good_ones=[val for ind, val in zip(one_zero_map,xldata['yaxis_data']) if ind==1]

bad_ones=[val for ind, val in zip(one_zero_map,xldata['yaxis_data']) if ind==0]

final_list=[good_ones,bad_ones]

plt.boxplot(final_list)

Just to be more clear on what I am looking for, I am looking for Python equivalent of R which is like this

# Boxplot of MPG by Car Cylinders

boxplot(mpg~cyl,data=mtcars, main="Car Milage Data",

xlab="Number of Cylinders", ylab="Miles Per Gallon")

or phython equivalent of graphlab as

sales.show(view='BoxWhisker Plot',x='zipcode',y='price')

解决方案

You can use the boxplot method directly from pandas DataFrames. This code is equivalent to your R example:

# statsmodels only needed to get the R mtcars dataset

import statsmodels.api as sm

mtcars = sm.datasets.get_rdataset('mtcars').data

mtcars.boxplot('mpg', by='cyl')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值