python - Appending to List after Pandas if else statement -


i'm trying append time value plotlist wherever dup column value false.

the df =

 lat                time      trip_id     diff  shifted  segment    dup  -7.12040 2015-12-24 02:03:10  18060.0  0.00003  0.00000        1  false  -7.12043 2015-12-24 02:03:12  18060.0  0.00000  0.00003        2  false  -7.12043 2015-12-24 02:03:14  18060.0  0.00003  0.00003        2   true  -7.12046 2015-12-24 02:03:16  18060.0  0.00003  0.00003        2   true  -7.12049 2015-12-24 02:03:19  18060.0  0.00003  0.00000        3  false  -7.12052 2015-12-24 02:03:22  18060.0  0.00000 -0.00473        4  false 

the code =

plotlist=[] def pullline(row):     if row['dup'] == false:         plotlist.append(row['time']) pullline(df) 

i had thought might work error valueerror: truth value of series ambiguous. use a.empty, a.bool(), a.item(), a.any() or a.all()

can explain a) going on here, , b) can avoid? don't understand how asking if false can ambiguous.

many thanks.

i guess can way:

plotlist = df.loc[df['dup'] == false, 'time'].values 

you're passing whole df parameter function, treating 1 row...

depending on want - array or list:

in [167]: df.loc[df['dup'] == false, 'time'].values out[167]: array(['2015-12-24 02:03:10', '2015-12-24 02:03:12', '2015-12-24 02:03:19',        '2015-12-24 02:03:22'], dtype=object)  in [168]: df.loc[df['dup'] == false, 'time'].tolist() out[168]: ['2015-12-24 02:03:10',  '2015-12-24 02:03:12',  '2015-12-24 02:03:19',  '2015-12-24 02:03:22'] 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -