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

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -