0

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.

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

Beat me to it :) Nice answer.
Added an alternate style - hope you don't mind :) Feel free to revert it if you don't want it in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.