Here is the relevant code that uses apply
, lambda
to process each row of the dataframe and creates a new column lat_decimal
to contain the result.
# Create dataframe
d6 = {'id':['a1','a2','a3'],
'lat_deg': [10, 11, 12],
'lat_min': [15, 30, 45],
'lat_sec': [10, 20, 30]
}
df6 = pd.DataFrame( data=d6 )
df6["lat_decimal"] = df6[["lat_deg","lat_min","lat_sec"]].apply(lambda row: row.values[0] + row.values[1]/60 + row.values[2]/3600, axis=1)
The resulting dataframe:-
id lat_deg lat_min lat_sec lat_decimal
0 a1 10 15 10 10.252778
1 a2 11 30 20 11.505556
2 a3 12 45 30 12.758333
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.