【发布时间】:2021-11-22 16:45:53
【问题描述】:
我有问题。 5 列具有可变类型(第 2 到 6 列)。如果这些主列 = 0,我需要对应的列(8 到 12)分别看到 0。
df.loc[df['CHT-05'] == 0, 'P CHT-05'] = 0
df.loc[df['CHT-07'] == 0, 'P CHT-07'] = 0
df.loc[df['CHT-09'] == 0, 'P CHT-09'] = 0
df.loc[df['BFR-01'] == 0, 'P BFR-01'] = 0
df.loc[df['JUB-45'] == 0, 'P JUB-45'] = 0
【问题讨论】:
-
上面带有变量名的代码可以工作,但是我想要一个更短的代码。请帮帮我好吗?
-
请使用
print(df.head().to_string(index=False))的输出更新您的帖子
标签: python pandas for-loop pandas-loc