Skip to content
Advertisement

Filter column value from other columns’ values and turn the results into multiple lists Pandas

JavaScript

The goal is: for column 1990-1993, if value == 1, return Country to 4 lists, I also want to set each list a #name of the year and don’t know how to do that.

here is my try:

JavaScript

I got the output as 4 lists of nans… The desired output would be

JavaScript

Advertisement

Answer

One way using dict comprehension with groupby on axis=1:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement