# 将负值转换为0
data2.loc[data2['本月费用'] < 0 ] = 0
想把列“本月费用”中的负值转换成0,但是现了整行都被转换成0的问题,怎么才能做到只转换单列的值呢
# 将负值转换为0
data2.loc[data2['本月费用'] < 0 ] = 0
想把列“本月费用”中的负值转换成0,但是现了整行都被转换成0的问题,怎么才能做到只转换单列的值呢
方法1:data2.loc[data2['本月费用'] < 0 ,'本月费用'] = 0
方法2: data2['本月费用'] = [0 if i <0 else i for i in data2['本月费用']]