Can't filter out something from a column from a dataframe. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can't filter out something from a column from a dataframe.

Lets say 'df' is a dataframe and 'x' is a column of it. So when I write df['x'] it shows all the elements of that column. There are total 100 elements in that column ( which also mean 100 rows). Now of these 100 values 90 are float and 10 are NaN. I want to write a simple line of code which will filter out the NaN values and will show the 90 values which are float. I tried writing below ones but not working: 1. df[dtype(df['x'])==float64)] 2.df[df.x.dtype==float64] Nothing is working. What is the proper way to write the code?

7th Jan 2021, 10:05 AM
Mir Abir Hossain
Mir Abir Hossain - avatar
2 Answers
+ 4
Thank you 《 Nicko12 》 it was a simple solution. I couldn’t think of it. I need to observe more.
7th Jan 2021, 10:22 AM
Mir Abir Hossain
Mir Abir Hossain - avatar
+ 2
You can use mask to filter and compare values or types. Here's an example https://code.sololearn.com/chhbNozbPf01/?ref=app
7th Jan 2021, 10:14 AM
noteve
noteve - avatar