gpt4 book ai didi

python - 如何从Excel中读取数据并设置数据类型

转载 作者:行者123 更新时间:2023-12-01 04:57:55 25 4
gpt4 key购买 nike

我正在尝试从 csv 文件读取纬度和经度数据,并使用 Harversine 公式连续计算方位角。

我必须从一行中获取纬度/经度,然后计算下一行中纬度/经度的方位角。

我更新了代码,现在收到此错误:

indexes = [x.index for x in self.objs]
AttributeError: 'numpy.float64' object has no attribute 'index'

我不知道如何将数组的数据类型设置为浮点型。我想知道是否有人可以帮助我解决这个问题?谢谢。

更新...下面是工作代码。

<小时/>
import pandas as p
import numpy as np

bearingdata = 'xxxxxx.csv'
data = p.read_csv(bearingdata)

lat = [float(i) for i in data.Lat]
lon = [float(j) for j in data.Lon]

lat1 = lat[0: (len(lat) -2)]
lon1 = lon[0: (len(lon) -2)]
lat2 = lat[1: (len(lat) -1)]
lon2 = lon[1: (len(lon) -1)]

然后 def() ......

最佳答案

使用 pyexcel,这项工作也可以轻松完成:

>>> import pyexcel as pe
>>> sheet = pe.load("xxxxx.csv")
>>> sheet.format(float)
>>> sheet.name_columns_by_row(0)
>>> lat = sheet.column["Lat"]
>>> lon = sheet.column["Lon"]
....# more processing here

关于python - 如何从Excel中读取数据并设置数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26953628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com