python - How to form tuple column from two columns in Pandas of only non empty values -


this extension of question

using

 df['new_col'] = zip(df.lat, df.long) 

to combine multiple columns tuple

how drop (or not add) empty elements (column) tuple should contain non-empty values

just give example:

instead of ('a','') or ('a',) display     ('a') 

also, there way convert tuple set

thanks helpful comments guys, here's worked me:

import copy def remove_empty(x):     c in copy.copy(x):          if not c:              x.discard(c)     return x  df['new_col'] = zip(df.lat, df.long) df['new_col'] = df['new_col'].apply(set) df['new_col'] = df['new_col'].apply(remove_empty) 

Comments

Popular posts from this blog

android - net_scheduler holding wakelock -

sql - MySQL : Getting Entries from a many-to-many table -

java - Retrieving data from database using jsp (Hibernate + Spring + Maven) -