我有一个这样的DataFrame:
In [207] SUE_df.iloc[45:59,354:359]
Out[207]:
PLNTSYS00013 PLNFI0800016 PLODLPL00013 PLTELL000023 PLONE0000014
2009-04-01 -2.7322 0.488461 -0.330779 -0.100912 -2.12907
2009-07-01 4.04982 3.49382 -0.298544 -0.181343 1.89539
2009-10-01 -3.57738 -5.08303 8.24463 -0.103642 0.643103
2010-01-01 -1.42976 0.325262 -0.058854 -0.555572 0.268437
2010-04-01 1.33034 -0.807921 0.191467 -0.311175 2.72122
2010-07-01 -0.0235675 -0.048386 0.258616 -0.171754 -2.8844
2010-10-01 0.660161 4.93671 0.297664 0.751903 -0.851329
2011-01-01 2.03963 -0.650254 0.223173 1.00279 0.114187
2011-04-01 5.06403 0.828365 -0.110528 0.244366 0.11977
2011-07-01 -1.18217 2.29948 0.521475 0.0705636 0.0486713
2011-10-01 0.118289 1.81084 0.198643 -0.768194 -0.833647
2012-01-01 0.148177 -0.0794947 0.0713122 -1.50967 -0.168698
2012-04-01 0.641605 -0.157657 0.036897 1.21578 -1.03026
2012-07-01 0.76635 -1.55429 -0.103827 0.217835 0.109092
我想获得具有SUE_df
的十分位等级的df,我编写了自己的方法来执行此操作,但是我一直认为必须有一种更简单的方法来执行此操作。我正在使用'.qcut(df,10, labels=False)
,但它仅适用于Series,不适用于DataFrame,因此我需要遍历各行,然后将它们插入新的df,这不是很复杂,但是需要一段时间。
我希望得到这样的结果:
for a in SUE_df.iloc[45:59,354:359].index:
SUE2.loc[a] = pd.qcut(SUE_df.iloc[45:59,354:359].loc[a], 5,labels=False ) + 1
Out[212]:
PLNTSYS00013 PLNFI0800016 PLODLPL00013 PLTELL000023 PLONE0000014
2009-04-01 1 5 3 4 2
2009-07-01 5 4 1 2 3
2009-10-01 2 1 5 3 4
2010-01-01 1 5 3 2 4
2010-04-01 4 1 3 2 5
2010-07-01 4 3 5 2 1
2010-10-01 3 5 2 4 1
2011-01-01 5 1 3 4 2
2011-04-01 5 4 1 3 2
2011-07-01 1 5 4 3 2
2011-10-01 3 5 4 2 1
2012-01-01 5 3 4 1 2
2012-04-01 4 2 3 5 1
2012-07-01 5 1 2 4 3
是否有任何DataFrame方法对整个df按行执行?