Resolved: conditional filtering on rows rather than columns

In this post, we will see how to resolve conditional filtering on rows rather than columns

Question:

Given a table
col_0 col_1 col_2
0 a_00 a_01 a_02
1 a_10 nan a_12
2 a_20 a_21 a_22

If I am returning all rows such col_1 does not contain nan, then it can be easily done by df[df['col_1'].notnull()], which returns
col_0 col_1 col_2
0 a_00 a_01 a_02
2 a_20 a_21 a_22

If I would like to return all columns such that its 1-th row does not contain nan, what should I do? The following is the result that I want:
col_0 col_2
0 a_00 a_02
1 a_10 a_12
2 a_20 a_22

I can transpose dataframe, remove rows on transposed dataframe, and transpose back, but it would become inefficient if dataframe is huge. I also tried
but the code gives me an error. Any ideas?

Best Answer:

Boolean indexing with loc along columns axis
Result

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com