【发布时间】:2019-12-10 05:44:08
【问题描述】:
我有一个数据框,其数据如下:
Run_1 Run_2 Run_3 Avg
5.26 6.08 1.8 2
273 0 0 23
5.26 6.08 1.8 1
它有形状
(2928, 501)
我想将所有值 > 0 更改为 0,并将当前所有值设置为 0 到 1,仅针对名称中包含子字符串 Run_ 的列。列数来自Run_1, Run_2, ... Run_500。条件更改不适用于除Run_1, Run_2, ... Run_500 之外的任何其他列。
所以,期望的输出是:
Run_1 Run_2 Run_3 Avg
0 0 0 2
0 1 1 23
0 0 0 1
我尝试了以下方法:
maxGen = np.max(df.filter(regex='Run_').values) + 5555.
df.loc[df.filter(regex='Run_') > 0] = maxGen
但我得到了错误:
ValueError: cannot copy sequence with size 500 to array axis with dimension 2928
编辑: 数据框中没有负值。
【问题讨论】:
-
将所有正值都改为零,负值呢,负值可能吗?
标签: python python-3.x pandas python-3.5