是否有 Geopy Python 函数将数据框列 (Latitude/Longitude) 从 "degree minute second" 转换为 "degree decimal"

Is there a Geopy Python function that converts dataframe column (Latitude/Longitude) from "degree minute second" to "degree decimal"

我为我的数据框 (df) 中的每一行应用了以下函数,并使用 Lat0/Lon0、方向(方位角)和距离(距离)我在“度”中得到了新的 Lat/Lon分秒":

def location(row):
    from geopy.distance import distance
    dist = row['dist']
    direction = row['azimuth']
    lat0 = 20
    lon0 = 20
    return distance(kilometers=dist).destination((lat0, lon0), direction)

df['coordinate'] = df.apply(lambda row: location(row), axis=1)

我想知道是否有一种方法可以在我的数据框中使用基于 df['coordinate'] 输出的 Lat 和 Lon(“degree decimal”)信息创建新的两列。

Out[]: 
                            time  zenith  azimuth      o3  uncertainty  flag  \
61 2019-01-24 15:02:57.983999999   66.90   121.72  241.85       4.9131     1   
62 2019-01-24 15:04:35.616000000   66.57   121.94  227.36       4.1773     1   
63 2019-01-24 15:06:13.248000000   66.25   122.16  232.97       3.4649     1   
64 2019-01-24 15:07:50.880000000   65.92   122.39  236.81       3.1841     1   
         dist                            coordinate  
61  51.578278   19 45m 16.3524s N, 20 25m 6.9961s E  
62  50.766056  19 45m 24.9176s N, 20 24m 39.7557s E  
63  49.998803   19 45m 32.885s N, 20 24m 13.9121s E  
64  49.227710  19 45m 40.8577s N, 20 23m 47.8847s E 

更新 已解决

def location(row, lat0, lon0):
    from geopy.distance import distance
    dist = row['dist']
    direction = row['azimuth']
    return distance(kilometers=dist).destination((lat0, lon0), direction).format_decimal()

df['coordinate'] = df.apply(lambda row: location(row, 20, 20), axis=1)

split_data = df.coordinate.str.split(', ')
df['lat'] = split_data.apply(lambda x: x[0])
df['long'] = split_data.apply(lambda x: x[1])

当前数据帧:

Out[]: 
                            time  zenith  azimuth      o3  uncertainty  flag  \
61 2019-01-24 15:02:57.983999999   66.90   121.72  241.85       4.9131     1   
62 2019-01-24 15:04:35.616000000   66.57   121.94  227.36       4.1773     1   
63 2019-01-24 15:06:13.248000000   66.25   122.16  232.97       3.4649     1   
64 2019-01-24 15:07:50.880000000   65.92   122.39  236.81       3.1841     1   
         dist                              coordinate                 lat  \
61  51.578278    19.75454233221212, 20.41861002686191   19.75454233221212   
62  50.766056  19.756921547635606, 20.411043240303318  19.756921547635606   
63  49.998803  19.759134724013204, 20.403864475793757  19.759134724013204   
64  49.227710  19.761349364643046, 20.396634631525913  19.761349364643046   
                  long  
61   20.41861002686191  
62  20.411043240303318  
63  20.403864475793757  
64  20.396634631525913 

如果您删除 .format_decimal(),您的 location 函数将 return Point 实例而不是字符串(参见 https://geopy.readthedocs.io/en/stable/#geopy.point.Point),其中十进制坐标可以很容易地被提取为属性:

df['point'] = df.apply(lambda row: location(row, 20, 20), axis=1)

df['lat'] = df['point'].apply(lambda point: point.latitude)
df['long'] = df['point'].apply(lambda point: point.longitude)