I have the following table loaded as a dataframe in Python using pandas
+--------+-------+------+
| Number | Col1 | Col2 |
+--------+-------+------+
| ABC | TRUE | SFG |
| BCD | TRUE | |
| CDE | FALSE | SFG |
| DEF | FALSE | |
| FEG | TRUE | JJI |
+--------+-------+------+
Number, Col2 - String; Col1 - Boolean
I want to select rows from this df using the following logic
IF Col1 = TRUE and Col2 is not null Select Number + "," + Col2
ELSE IF Col1 = TRUE and Col2 is null Select Number
ELSE IF Col2 is not null and Col1 = FALSE Select Col2
In the above case, the output should be a list with the following values
["ABC", "SFG", "BCD", "FEG", "JJI"] //Removing the repetition too ("SFG")
How do I go about implementing this logic in Python using Pandas?
['ABC,SFG', 'BCD', 'SFG', nan, 'FEG,JJI']following your logicnumpy.wherestatements.