0

I would like to do an if test on the 'ave_data' DataFrame below:

ave_data=

Time ------------ F7 --------------- F8 --------------- F9
00:00:00 ---- 43.005593 ---- -56.509746 ---- 25.271271
01:00:00 ---- 55.114918 ---- -59.173852 ---- 31.849262
02:00:00 ---- 63.990762 ---- -64.699492 ---- 52.426017

Specifically, I would like to test if any of the values are less than 0.05 and output 1 if they are not, and 0 if they are, so that the output (named, for example, 'tested_ave_data') looks like this:

tested_ave_data=

Time ------------ F7 --- ------- F8 ---------- F9
00:00:00 -------- 1 ------------ 0 ------------ 1
01:00:00 -------- 1 ------------ 0 ------------ 1
02:00:00 -------- 1 ------------ 0 ------------ 1

Can anyone help me develop a code to do this? I've searched for ways to do this for a long time now but not been successful.

1 Answer 1

1

you don't need to "develop" any code if I understand your question correctly. Just use a Boolean mask -- everything is already implemented in pandas.

import pandas as pd

a = [[2., .3, 4., 5.], [.8, .03, 0.02, 5.]]
df = pd.DataFrame(a)
df

enter image description here

df <= 0.05

enter image description here

df = df < 0.05
df.astype(int)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

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.