简体   繁体   English

在 pandas dataframe 中将度分秒 (DMS) 列转换为十进制度

[英]Converting degree minute second (DMS) columns to decimal degrees in pandas dataframe

I have a data frame like the below and would like to convert the Latitude and Longitude columns in Degree, Minute, Second format into decimal degrees and want the updated table with other column我有一个如下所示的数据框,想将度、分、秒格式的纬度和经度列转换为十进制度,并希望更新表与其他列

any help would be appreciated任何帮助,将不胜感激

在此处输入图像描述

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.这是使用apply的相关代码, lambda处理 dataframe 的每一行并创建一个新列lat_decimal来包含结果。

# 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:-由此产生的 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将带有度分秒 (DMS) 坐标的熊猫数据框转换为十进制度数 - Converting pandas data frame with degree minute second (DMS) coordinates to decimal degrees 如何将度分秒转换为度小数 - How to convert degree minute second to degree decimal 如何使用 pandas 将度分秒 (DMS) 数据直接从 a.CSV 文件读取到 dataframe 作为字符串? - How to read Degree Minute Seconds (DMS) data directly from a .CSV file using pandas into a dataframe as strings? 是否有一个 Geopy Python function 将 dataframe 列(纬度/经度)从“度分秒”转换为“度十进制” - Is there a Geopy Python function that converts dataframe column (Latitude/Longitude) from “degree minute second” to “degree decimal” 在 Python 中将 DD(十进制度)转换为 DMS(度分秒)? - Convert DD (decimal degrees) to DMS (degrees minutes seconds) in Python? 将 Pandas 数据框的行转换为列 - Converting Pandas dataframe rows to columns 将pandas数据帧中的行转换为列 - Converting rows in pandas dataframe to columns 将熊猫数据框中的列转换为日期时间 - converting columns in pandas dataframe into datetime 通过使用第二个索引作为列将pandas多索引系列转换为数据帧 - Converting a pandas multi-index series to a dataframe by using second index as columns 区分 pandas dataframe 中的十进制和字符串列 - distinguish decimal and string columns in a pandas dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM