Home > Enterprise >  How to drop rows of a column having float datatype and are values less than 1
How to drop rows of a column having float datatype and are values less than 1

Time:12-07

I am new to pandas and I have just started to learn how to analyze a data.

In order to explain y problem, Consider this table as df.csv

Name Age Height
A 2 5.7
B 4 5.4
C 8 5.9
D 4 0.6

From this file, I want to drop the row that has Height less than 1 so that when i pass this command, it would delete the specified row and show me this:

Name Age Height
A 2 5.7
B 4 5.4
C 8 5.9

I wrote this command:

dec = df[df['Height']<0.0].index
df.drop(dec,inplace=true)
df

but it is showing me this:

Name Age Height
A 2 5.7
B 4 5.4
C 8 5.9
D 4 0.6

instead of :

Name Age Height
A 2 5.7
B 4 5.4
C 8 5.9

is there a way to achieve this?

CodePudding user response:

dec = df[df['Height'] < 1.0].index
df.drop(dec, inplace=True)

True and False are written in capital letters and the check is needed for 1 and not for 0.

  • Related