我正在尝试根据数据框的其他列对现有数据框的列进行操作。
例如:
if (df['col1']== 'this is') & (df['col2'] == 30) & (df['col3'] <= '2020-01-01'):
df['Value'] = 0
在这里,我试图为满足Value
语句中条件的if
列的每个元素分配值0。
但是我得到以下错误:
系列的真值不明确。使用a.empty,a.bool(),a.item(),a.any()或a.all()
答案 0 :(得分:1)
使用np.where
可获得更好的效果:
import numpy as np
df['Value'] = np.where(((df['col1']== 'this is') & (df['col2'] == 30) & (df['col3'] <= '2020-01-01')), 0, df['Value'])
答案 1 :(得分:1)
您可以使用.loc
upi://pay?pa=<VPA>&am=<AMOUNT>