我想对方法列进行分组,此df的方法列是分类变量,但无法对其进行分组。当我运行此代码时,结果是分开的,我的意思是不归为方法。您能帮我吗?
import seaborn as sns
df=sns.load_dataset("planets")
df
def filter_functionn(x):
return x["orbital_period"].std()>50
df.groupby(["method"]).filter(filter_functionn)
使用GroupBy.transform
了重复合计值,因此可能通过过滤器boolean indexing
:
df1 = df[df.groupby("method")["orbital_period"].transform('std') > 50]
print (df)
method number orbital_period mass distance year
0 Radial Velocity 1 269.300000 7.10 77.40 2006
1 Radial Velocity 1 874.774000 2.21 56.95 2008
2 Radial Velocity 1 763.000000 2.60 19.84 2011
3 Radial Velocity 1 326.030000 19.40 110.62 2007
4 Radial Velocity 1 516.220000 10.50 119.47 2009
... ... ... ... ... ...
1030 Transit 1 3.941507 NaN 172.00 2006
1031 Transit 1 2.615864 NaN 148.00 2007
1032 Transit 1 3.191524 NaN 174.00 2007
1033 Transit 1 4.125083 NaN 293.00 2008
1034 Transit 1 4.187757 NaN 260.00 2008
[1035 rows x 6 columns]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句