Consider
>>> df
0 1 2 3
0 0.0 1.0 NaN 23
1 NaN 1.0 23.0 4
2 NaN NaN 1.0 0
3 0.0 NaN NaN 1
>>> df.apply(lambda s: s.dropna().iloc[:2].reset_index(drop=True), axis=1)
0 1
0 0.0 1.0
1 1.0 23.0
2 1.0 0.0
3 0.0 1.0
edit: this will give you the first two (or n
) non missing values from each row. Your question is unclear on whether this is sufficient.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.