Pandas DataFrame.apply: create new column with data from two columns

后端 未结 1 897
后悔当初
后悔当初 2021-01-14 08:27

I have a DataFrame (df) like this:

PointID  Time                 geojson
----     ----                 ----     
36F      2016-04-01T03:52:30  {\'type\': \'P         


        
相关标签:
1条回答
  • 2021-01-14 09:05

    You need DataFrame.apply with axis=1 for processing by rows:

    df['new'] = df.apply(lambda x: inject_time(x['geojson'], x['Time']), axis=1)
    
    #temporary display long string in column
    with pd.option_context('display.max_colwidth', 100):
        print (df['new'])
    
    0    {'type': 'Point', 'coordinates': [3.961389, 43.123, '2016-04-01T03:52:30']}
    1    {'type': 'Point', 'coordinates': [3.543234, 43.789, '2016-04-01T03:52:50']}
    Name: new, dtype: object
    
    0 讨论(0)
提交回复
热议问题