0

I got 2 pandas Series objects, both are of 1 column. Each element of the first one is a list of floats, each element of the second one is bool. Len is equal. first one:

0              [190, 2000]
1        [250, 1500, 2500]
2            [12.7, 2.700]
3       [22.4, 1750, 2750]
4            [11.5, 4.500]
               ...        
8123         [113.7, 4000]
8124    [24, 1.900, 2.750]
8125           [190, 2000]
8126     [140, 1800, 3000]
8127     [140, 1800, 3000]
Name: torque, Length: 8128, dtype: object

second one:

0        True
1        True
2       False
3       False
4       False
        ...  
8123     True
8124    False
8125     True
8126     True
8127     True
Name: torque, Length: 8128, dtype: object

I also have function with two arguments - list object and bool object. It processes list object depending on bool value and returns tuple of 2 element always. So what I wanna do is to get all the element from the first Series through the function also giving it corresponding bool values from the second Series and receive third Series consisting of 2 columns (cause function returns tuple of 2 elements). Also the first Series has some NaN values instead of lists in some lines so I need to watch it as well. In this case I need to write NaN and NaN to the resulting Series.

I can apply cycles and complicated constructions but I am sure there must be an easier way using pandas classes and functions.

  • Possible duplicate of https://stackoverflow.com/questions/13331698/how-to-apply-a-function-to-two-columns-of-pandas-dataframe (passing multiple columns to function with apply) and https://stackoverflow.com/questions/23586510/return-multiple-columns-from-pandas-apply (return multiple columns from apply) – Nick ODell Feb 03 '23 at 17:09

0 Answers0