How to form tuple column from two columns in Pandas

后端 未结 4 1808
天命终不由人
天命终不由人 2020-11-28 02:43

I\'ve got a Pandas DataFrame and I want to combine the \'lat\' and \'long\' columns to form a tuple.


Int64Index         


        
4条回答
  •  余生分开走
    2020-11-28 03:00

    Get comfortable with zip. It comes in handy when dealing with column data.

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

    It's less complicated and faster than using apply or map. Something like np.dstack is twice as fast as zip, but wouldn't give you tuples.

提交回复
热议问题