I want to get all non nan values in a dataframe like:
foo foo2 foo3 foo4
a NY WA AZ NaN
b DC NaN NaN NaN
c MA CA NaN NaN
output:
[NY, WA, AZ, DC, MA, CA]
I couldn't find an exact answer for this question, so when I combined several answers into one,
thought to share the answer:
df.stack().values
The trick is that stack() is removing nans while stacking the values, the rest is just standard way of getting dataframe values into list.
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.