0

I have a column called key_resp_5_rt and in it I would like to remove any rows that are under 300ms (it is a reaction time column)

for filename in files:
try:
    df=pd.read_csv(filename)

    df['key_resp_5.rt']

Can someone tell me if this code underneath can remove rows with rt's under 0.3 seconds?

    df[df['key_resp_5.rt'] > 0.3] 

When I check afterwards the rows with values lower than 0.3 are still there and I can't figure out why

unknown
  • 322
  • 6
  • 25
abc_95
  • 179
  • 8
  • what's the datatype for `key_resp_5.rt` (`print(df.dtypes)`)? One guess is that it's a string, not a float. Also you have to assign the result back to the original dataframe: `df = df[[...]]` – pault Jan 24 '20 at 16:48
  • 3
    Basically pandas dataframes are not mutable, you therefore need to assign the df again `df = df[df['key_resp_5.rt'] > 0.3] ` – nickyfot Jan 24 '20 at 16:50
  • @nickthefreak Or alternatively assign to a new variable. – Code-Apprentice Jan 24 '20 at 16:54

1 Answers1

0

You need to assign the return value to the same variable again in order to replace it. This does not happen in-place:

df = df[df['key_resp_5.rt'] > 0.3]

m02ph3u5
  • 3,022
  • 7
  • 38
  • 51