0

I have a data frame as shown below.I need to select all rows for which the value of first column named index is less than 0.3768.

I have found some answers in stack over flow,but none of them is working in my case enter image description here

I tried to create a data frame which contains all rows where the column(named index as shown in yellow) value .Below is my code it is throwing some error.May I know where I went wrong.

df2 = df_thd_funct_mode2_perf['index'] <= 0.3768
df2

The error obtained is given below.

'<=' not supported between instances of 'str' and 'float'

Hari
  • 333
  • 6
  • 18

1 Answers1

1

You're looking for:

df2 = df_thd_funct_mode2_perf[df_thd_funct_mode2_perf['index'] <= 0.3768]

A short explanation:

We're saying here: Take all of the rows and columns of df_thd_funct_mode2_perf for which [df_thd_funct_mode2_perf['index'] <= 0.3768] and then save this to df2

JED HK
  • 216
  • 1
  • 8
  • Thank you, it is giving me only the 0th row .I need all the rows where index less than 0.3768 – Hari Jul 20 '22 at 10:15
  • 1
    Ah, this is because the column is name index and using df.index takes the index instead. I've updated the answer accordingly. The code will now work. – JED HK Jul 20 '22 at 10:21