I am trying to read in latitude and longitude data from a csv file and calculate bearing successively using harversine formula.
我正在尝试从csv文件中读取纬度和经度数据,并使用harversine公式依次计算轴承。
I have to pick up the lat/lon from one row then calculate bearing against the lat/lon in the next row.
我必须从一排取拉/拉,然后计算下一排的拉/拉。
I updated the codes and now I am getting this error:
我更新了代码,现在我得到了这个错误:
indexes = [x.index for x in self.objs]
AttributeError: 'numpy.float64' object has no attribute 'index'
I can't figure out how I can set data type to float for array. I wonder if someone can help me on this? Thank you.
我不知道如何设置数据类型为float for array。我想知道是否有人能在这件事上帮助我?谢谢你!
Update ... below is the working code.
更新……下面是工作代码。
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)]
then def() .....
.....然后def()
2 个解决方案
#1
0
With pyexcel, this job can be done easily too:
使用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
#2
1
I just want to re-iterate ... below is the final code.
我只是想重复一遍……下面是最终的代码。
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)]
#1
0
With pyexcel, this job can be done easily too:
使用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
#2
1
I just want to re-iterate ... below is the final code.
我只是想重复一遍……下面是最终的代码。
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)]