Hi I am struggling with the following problem:
given a dataframe with columns name and variable I would like to create 2 lists:
- list_names_nan containing the names for which all the values in the variable column are nan
- list_names_not_nan containing the names for which at list 1 value in the variable column is not nan
below an example
import pandas
import numpy
df = pandas.DataFrame(data=[['x',1],['y',2],['x',4],['z',numpy.nan],
['x',numpy.nan],['y',3],['x',numpy.nan],['z',numpy.nan],],
columns=['name','variable'])
df:
name variable
0 x 1.0
1 y 2.0
2 x 4.0
3 z NaN
4 x NaN
5 y 3.0
6 x NaN
7 z NaN
the desired output should be
list_names_nan = [z]
list_names_not_nan = [x,y]