1

I have df like This mention in below

    a   b   marks
 0  1   2    25.0
 1  2   3    96.2
 2  3   6    87.0
 3  4   5    32.2

I want two dataframe using some condition, conditions are if marks are >70.0 then I want df_pass =

      a   b   marks
   1  2   3    96.2
   2  3   6    87.0

and else <70.0 in df_fail

      a   b   marks
  0   1   2    25.0
  3   4   5    32.2
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45

2 Answers2

1

You can apply a filter using DataFrame.apply and you can use a lambda for your condition:

pass_lambda = lambda x: x['marks'] > 70
df_pass = df[df.apply(pass_lambda, axis=1)]
df_fail = df[df.apply(lambda x: not pass_lambda(x), axis=1)]
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
0

Using groupby you can split your dataframe like this

df1, df2 = [x for _, x in df.groupby(df['marks'] > 70)]
Pawan Jain
  • 815
  • 3
  • 15