how to make changes to a existing column based on multiple conditions in python csv

91
April 02, 2022, at 1:30 PM

So I am working on data processing and I want to make changes to a column called "temp_coil" based on the condition in other columns.

This is the one I made and it is giving me error.

df.temp_coil[df.outdoor_temperature < 20 & df.cooling_state == 1 & df.temp_coil == 0] = 4500

I want the answer to be 4500 if outdoor_temperature column is less than 20, cooling_state column is 1 and temp_coil column itself is 0. All the conditions need to be met.

The error it is giving me is type and value error when I run it. If this is already answered please let me know, I couldn't find an example that matched my problem.

Answer 1

You must use parentheses so that the truth table is unambiguous. For your example, the correct code would be:

df.temp_coil[(df.outdoor_temperature < 20) & (df.cooling_state == 1) & (df.temp_coil == 0)] = 4500

Or:

df.temp_coil[df.outdoor_temperature.lt(20) & df.cooling_state.eq(1) & df.temp_coil.eq(0)] = 4500
READ ALSO
How do I display role members separately from online members?

How do I display role members separately from online members?

I searched for my problem in the API Reference, but I didn't find anything

80
Fast Python outer difference of list

Fast Python outer difference of list

I want to compute the difference between every element in a Python list of equally long lists and put it into a Numpy array

69
OpenCV VideoWriter Error &quot;dimensions too large for MPEG-4&quot;

OpenCV VideoWriter Error "dimensions too large for MPEG-4"

I have some frames (dimensions: 8192x2160) that are generated from concatenating two 4096x2160 frames side by sideWhen writing these frames to a video file using OpenCV VideoWriter, I get this error: dimensions too large for MPEG-4

89