Home > Net >  extract specific rows using pandas
extract specific rows using pandas

Time:12-14

I tried extracting only specific rows greater than or equal to 30 using python.

Column_A
20
30
40
50

However, I got an error "

'>=' not supported between instances of 'str' and 'int'

" . Please help me to solve this error.

df = pd.DataFrame(df) df[df.Column_A >= 30]

but I got an error "'>=' not supported between instances of 'str' and 'int'"

CodePudding user response:

Convert the text column to an integer before comparing:

df = pd.DataFrame(df)
df = df[df.Column_A.astype(int) >= 30]

That being said, given that you want to treat Column_A as a number, perhaps you should convert it to integer.

CodePudding user response:

This happens because df.Column_A is a str and 30 is an int. Pretty sure you can fix this by putting int() before df.Column_A, like this:

df = pd.DataFrame(df) df[int(df.Column_A) >= 30]
  • Related