If I have the following DataFrame:
>>> df_1 = pd.DataFrame({'A':[-1, 2, 3],
'B':[4, -5, 6],
'C':[7, 8, -9]},
index=pd.to_datetime(['2017-01-01 00:01:00', '2017-01-01 00:02:00', '2017-01-02 00:01:00']))
>>> df_1
A B C
2017-01-01 00:01:00 -1 4 7
2017-01-01 00:02:00 2 -5 8
2017-01-02 00:01:00 3 6 -9
How would I replace all of the negative values in a specific column with something else? For example, if I want to replace all of the negative values in the 'B' column but none of the others with, say 0, the following would be my result.
>>> df_2
A B C
2017-01-01 00:01:00 -1 4 7
2017-01-01 00:02:00 2 0 8
2017-01-02 00:01:00 3 6 -9
df_1['B'][df_1['B'] < 0] = 0work for you?