我有一个多索引数据框为:
df =
sta1 sta2 ... stan
coef e p coef e p ... coef e p
t 3 0.1 0.001 2 0.1 0.001 1 0.1 0.01
u 3 0.2 0.01 3 0.01 0.01 2 0.1 0.001
v 2 0.1 0.001 4 0.1 0.1 2 0.001 0.001
我想设一个条件,如果p> 0.01,则coef = nan。我的结果看起来像:
df =
sta1 sta2 ... stan
coef e p coef e p ... coef e p
t 3 0.1 0.001 nan 0.1 0.1 1 0.1 0.01
u 3 0.2 0.01 3 0.01 0.01 nan 0.1 0.1
v 2 0.1 0.001 nan 0.1 0.1 2 0.001 0.001
我很感谢有人指导我。谢谢你。
我在随机数据上对此进行了测试,请告诉我它是否适用于您的示例:
for multindex in df.columns.values:
if multindex[1] == 'p':
df[(multindex[0], 'coef')] = np.where(df[multindex] > 0.01, np.nan, df[(multindex[0], 'coef')])
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句