The Python Oracle

Applying conditional statements on lists stored in Dataframe cell

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow

--

Chapters
00:00 Question
01:34 Accepted answer (Score 1)
01:57 Thank you

--

Full question
https://stackoverflow.com/questions/7410...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #list #dataframe #booleanlogic

#avk47



ACCEPTED ANSWER

Score 1


You can use the normal > operator and then use agg or apply to get the desired output:

(df > 8000000).apply(list, axis=1)

0    [False, True, False]
1     [False, True, True]

example:

df = pd.DataFrame({'202201': [7180516.0, 4868058.0], '202202': [433433740.0, 452632806.0], '202203': [5444119.0, 10000000.0]})
df['seqToFs'] = (df > 8000000).apply(list, axis=1)