coverting false results to true if one came true

66 Views Asked by At

I have a boolen series of true and false in a data frame. what i need is how to covert the rest false results to true in case i found only one true. Thank you . For example a coulmn df["Test"]= [false,false,true,false ,true ,false]

I need to get it df["Test"] = [false,false,true,true,true,true]

Bear in mind that the data frame contains a coulmn for data df["Date"]and coulmn for time df["Time"]

I have tried many buy can figure it out Thank you

1

There are 1 best solutions below

6
On

Use idxmax:

df.loc[df.index>df['test'].idxmax(), 'test'] = True

EDIT

Because OP's original data is String, so convert it to Boolean firstly.

import ast
df['test'] = df['test'].apply(ast.literal_eval)

df.loc[df.index>df['test'].idxmax(), 'test'] = True