1

I have got DataFrame with lists:

deviceId  timeInMilliseconds           callState  \
0  e4774cdda0793f86414e8b9140bb6db4       1455233230229  CALL_STATE_OFFHOOK   
1  e4774cdda0793f86414e8b9140bb6db4       1455233232239     CALL_STATE_IDLE   
2  270c1b084f3f146eb5787075158d9c53       1455233316723  CALL_STATE_OFFHOOK   
3  270c1b084f3f146eb5787075158d9c53       1455233324391     CALL_STATE_IDLE   
4  270c1b084f3f146eb5787075158d9c53       1455234721731  CALL_STATE_OFFHOOK   

  number  numberType      time        data day_of_the_week  \
0  609665996           0  00:27:10  2016-02-12               5   
1  609665996           0  00:27:12  2016-02-12               5   
2  126301484           1  00:28:36  2016-02-12               5   
3  126301484           1  00:28:44  2016-02-12               5   
4  126301484           1  00:52:01  2016-02-12               5   

I want to get all data from those DataFrame when callState is equal to CALL_STATE_IDLE.

I tried like that:

data_all = [x for x in data if (x['callState'] == 'CALL_STATE_IDLE') ]   

but I have 'TypeError: string indices must be integers'.

Could you help me please?

2 Answers 2

4

I think, you need to be doing

data_all = data[data['callState'] == 'CALL_STATE_IDLE']

data_all

                           deviceId  timeInMilliseconds        callState  \
1  e4774cdda0793f86414e8b9140bb6db4       1455233232239  CALL_STATE_IDLE
3  270c1b084f3f146eb5787075158d9c53       1455233324391  CALL_STATE_IDLE

      number  numberType      time        data  day_of_the_week
1  609665996           0  00:27:12  2016-02-12                5
3  126301484           1  00:28:44  2016-02-12                5
Sign up to request clarification or add additional context in comments.

Comments

0

Also, using query

In [871]: df.query('callState == "CALL_STATE_IDLE"')
Out[871]:
                           deviceId  timeInMilliseconds        callState  \
1  e4774cdda0793f86414e8b9140bb6db4       1455233232239  CALL_STATE_IDLE
3  270c1b084f3f146eb5787075158d9c53       1455233324391  CALL_STATE_IDLE

      number  numberType      time        data  day_of_the_week
1  609665996           0  00:27:12  2016-02-12                5
3  126301484           1  00:28:44  2016-02-12                5

Comments

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.