python - 我可以在 Python 中使用什么代码将 40,000 行纬度和经度数字(以弧度表示)转换为笛卡尔坐标?
问题描述
下表是我正在使用的数据的示例。
unimportant latitude longitude lat long
a 52.927700 -3.243150 0.975123 -0.054621
b 54.396837 -1.680645 0.959385 -0.029333
c 52.902610 -1.473000 0.623323 -0.029691
d 51.541824 0.081160 0.899576 0.000417
e 51.073047 -0.423974 0.705355 -0.009382
:
:
我有一个有 5 列和 40000 行的表。1 列并不重要。第 2 列和第 3 列以度为单位显示“经度”和“纬度”,第 4 列和第 5 列以弧度显示标题为“纬度”和“经度”的纬度和经度。我的任务是添加 3 个新列 x、y、z,它们显示基于“lat”和“long”的笛卡尔坐标。我假设 z 代表海拔但是我不完全确定如何计算它。
如何计算 x、y、z 并将它们添加到表格中?
我已经尝试使用本网站上类似问题的答案中显示的代码,但是我得到 TypeError: must be real number, not str 错误。
def Cartesian_coordinates(lat,long):
R = 6371
x = R * math.cos(lat) * math.cos(long)
y = R * math.cos(lat) * math.sin(long)
z = R * math.sin(lat)
return x,y,z
使用调用函数
Cartesian_coordinates('lat', 'long')
只有产量
TypeError: must be real number, not str
解决方案
Cartesian_coordinates(df.latitude, df.longitude)
您应该将 args 作为值而不是字符串,例如:
'df.latitude' - this is string
df.latitude - this is value with type of df.latitude
推荐阅读
- ruby-on-rails - 错误:未定义的变量:“$alert-padding-y”
- pug - need to access location.hash in jade, wintersmith
- javascript - 刷新后如何使javascript倒计时继续
- mysql - 如何获取所有父母ID
- c# - 试图从非常大的数据中检索mysql中多个相关表的数据
- sql-server - 如何使用 c#.net 从组合框中的 NpgsqlConnection 获取所有数据库的列表
- paw-app - Paw - 一种在请求之间移动时使所选请求/响应选项卡保持粘性的方法
- node.js - 登录后重定向到个人资料网址
- oauth-2.0 - LinkedIn API 未授权_范围_错误
- c - 在宏定义中转义结构字段