can someone tell me why filtering a dataframe based on a column value does not apply the filter, instead it fills the other columns with nan values, as the following pictures show
Asked
Active
Viewed 1,239 times
-2
-
6Please do not link or embed external images of source code or data. Images make it difficult to efficiently assist you as they cannot be copied and offer poor usability as they cannot be searched. See: [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/q/285551/15497888) If you need assistance formatting a small sample of your DataFrame as a copyable piece of code for SO see [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888). – Henry Ecker Dec 23 '21 at 23:15
2 Answers
0
To test a column for NaN, use isna()
. See example below. Hope this is helpful, please leave a comment if something doesn't work
import pandas as pd
df = pd.DataFrame(data={"col1": [1,2], "col2": ["three",float('nan')]})
df[df.col2.isna()]
Output
col1 | col2 | |
---|---|---|
1 | 2 | nan |

user23952
- 578
- 3
- 10
0
Please don't link images to external sources, and use code blocks. Easily accessible data in questions is critical to reproducing the problem.
import numpy as np
import pandas as pd
dates = pd.date_range("20211223", periods=6)
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD"))
print(f"{df[df['A'] > 1]}")
You were mostly on the right track. Instead on df[df['TYPE' == 'RNA']]
you should use df[df['TYPE'] == 'RNA']

Anu
- 318
- 1
- 11