I have the following df:
mask = df.apply(lambda row: True if row.isnull().any() else False, axis=1)
df[HAS_MISSING_VALUES] = mask
date kpi1 kpi2 kpi3 location has_missing_values
0 2019-01-25 147.0 nan 82.876859 team1 True
1 2019-01-26 147.0 41.0 71.178657 team1 False
2 2019-01-27 nan 42.0 81.812117 team2 True
3 2019-01-28 147.0 42.0 75.754279 team2 False
4 2019-01-29 nan 42.0 nan team4 True
5 2019-01-30 nan nan nan team4 True
I need to create a new column that for each row contains its null values names.
so for example the output would be:
date kpi1 kpi2 kpi3 location missing_kpis
0 2019-01-25 147.0 nan 82.876859 team1 [kpi2]
1 2019-01-26 147.0 41.0 71.178657 team1 []
2 2019-01-27 nan 42.0 81.812117 team2 [kpi1]
3 2019-01-28 147.0 42.0 75.754279 team2 []
4 2019-01-29 nan 42.0 nan team4 [kpi1,kpi3]
5 2019-01-30 nan nan nan team4 [kpi1,kpi2,kpi3]
but been stuck from there
question from:
https://stackoverflow.com/questions/65867918/pandas-list-all-the-columns-that-have-null-values-for-each-row 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…