我想随机设置等于NaN的数据帧值,以获得一定百分比的NaN。 因此,从以下数据帧:
name IS_030_EBITDA IS_09_PostTaxResult
0 EISMA MEDIA GROEP B.V. NaN 1292.0
1 EISMA MEDIA GROEP B.V. 2280.0 1324.0
2 DUNLOP B.V. 43433.0 1243392.0
3 DUNLOP B.V. 2243480.0 1324.0
我希望我的数据帧有25%的值等于NaN(下面的NaN只是一个示例,必须随机完成):
name IS_030_EBITDA IS_09_PostTaxResult
0 EISMA MEDIA GROEP B.V. NaN 1292.0
1 EISMA MEDIA GROEP B.V. 2280.0 1324.0
2 DUNLOP B.V. 43433.0 NaN
3 DUNLOP B.V. 2243480.0 1324.0
所以需要了解的是,我不希望将25%的行或列设置为NaN,我希望在最终的数据帧中有25%的值等于NaN
谢谢你的帮助
如果我理解正确,您希望均匀地选择25%的单元格。这意味着您不能先选择记录(这会扭曲分布)。以下解决方案适用于25%的电池:
结果:
你想做这样的事吗
df原件:
df修改:
注:
“df_样本=df.样本(2)”——>;您可以添加逻辑以选择总样本记录的25%,并替换值2。例如:
相关问题 更多 >
编程相关推荐