There is a variable df. Its values ​​are:

55 -316 148 -126 109 -168 41 -333 85 -123 70 -11 35 -97 190 -104 42 -136 144 -22 194 -64 23 -669 

How to separate this one variable into two different, in one - positive values, in another negative? The order of numbers must be preserved.

    1 answer 1

    Example:

    Source DataFrame:

     In [31]: df Out[31]: col 0 55 1 -316 2 148 3 -126 4 109 5 -168 6 41 7 -333 8 85 9 -123 10 70 11 -11 12 35 13 -97 14 190 15 -104 16 42 17 -136 18 144 19 -22 20 194 21 -64 22 23 23 -669 

    positive values:

     In [32]: df_pos = df[df['col'] > 0] 

    negative values:

     In [33]: df_neg = df[df['col'] < 0] 

    Result:

     In [34]: df_pos Out[34]: col 0 55 2 148 4 109 6 41 8 85 10 70 12 35 14 190 16 42 18 144 20 194 22 23 In [35]: df_neg Out[35]: col 1 -316 3 -126 5 -168 7 -333 9 -123 11 -11 13 -97 15 -104 17 -136 19 -22 21 -64 23 -669 
    • Thank you for what you need - Jon S.