1

I have data

                     date                    id           request 
0     2016-06-17 09:25:05  [email protected]  GET HTTP/1.1   
1     2016-06-17 09:25:07  [email protected]     POST HTTP/1.1   
2     2016-06-17 09:25:47  [email protected]  CONNECT HTTP/1.1   
3     2016-06-17 09:25:47  [email protected]     POST HTTP/1.1   
4     2016-06-17 09:25:49  [email protected]  CONNECT HTTP/1.1 

I need to iterate string and 'GET' not in df['request'] I want to delete string from df.

Desire output

               date                    id           request 
0     2016-06-17 09:25:05  [email protected]  GET HTTP/1.1

I try df = df['GET' in df.request] but it returns

KeyError: False

1 Answer 1

2

You need boolean indexing with mask created by str.contains:

print (df.request.str.contains('GET'))
0  2016-06-17     True
1  2016-06-17    False
2  2016-06-17    False
3  2016-06-17    False
4  2016-06-17    False

print (df[df.request.str.contains('GET')])
                  date                    id       request
0 2016-06-17  09:25:05  [email protected]  GET HTTP/1.1

EDIT by comment:

For comparing column size use [], because size is function:

df_upd = df_upd[df_upd['size'].astype(int) > 3000]
Sign up to request clarification or add additional context in comments.

6 Comments

Can you say, why df_upd = df_upd[int(df_upd.size) > 3000] return keyerror? I also need to compare size(I have this column), and if it less that 3000, delete that string
You need astype for casting to int - df_upd = df_upd[df_upd.size.astype(int) > 3000]
it also return KeyError: True
Hmmmm, there is another problem - size is function. So you need [] - df_upd = df_upd[df_upd['size'].astype(int) > 3000]
btw, I have similar issues very often, because I like column names with same names as function like count, size...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.