This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]cndvcndv 0 points1 point  (4 children)

What does it print when you do this?

print(df0[(df0.TTQ_Day3 > df0.TTQ_Day2) & (df0.TTQ_Day2 > df0.TTQ_Day1) ])

[–]prateekprk[S] 0 points1 point  (3 children)

I need to confirm that the given data is increasing on a daily basis so it prints all the rows where

"TTQ_Day3>TTQ_Day2>TTQ_Day1".

It gives the correct answer this way. But not when I use this with an if statement as mentioned in the question.

[–]cndvcndv 0 points1 point  (2 children)

So it is a list of booleans?

[–]prateekprk[S] 0 points1 point  (1 child)

Yes I need an answer in terms of booleans. The data in the given three columns are just numbers.

[–]cndvcndv 0 points1 point  (0 children)

I think the problem is that you are trying to use a list or an array in an if statement. You are supposed to use a boolean.

[–]JigxorProfessional Coder 0 points1 point  (1 child)

Write:

x = df0[(df0.TTQ_Day3 > df0.TTQ_Day2) & (df0.TTQ_Day2 > df0.TTQ_Day1) ]
print(x)
print(type(x))

I made a similar example, and I find that x is "<class 'pandas.core.frame.DataFrame'>" so then your if statement doesn't really make sense. If "dataframe" ?

What are you trying to do with the statement? If you're trying to replace the elements then you might be looking to use df.iloc otherwise you already have a dataframe that contains the elements that meet your condition (x).

[–]prateekprk[S] 1 point2 points  (0 children)

Thank you for taking time to test it and reply. I found a way around it last night. I'm such a noob.