Я пытаюсь написать простую программу, которая импортирует файл CSV через pandas, выполняет геолокацию с использованием этого модуля и записывает результаты в новый файл CSV.
Модуль, который я использую, возвращает Dict, который я мог бы разделить на разные столбцы, но я не могу найти какой-либо способ сделать это.
Образец данных, с которыми я работаю:
ReportTime,ConvertedLat,ConvertedLong
2018-05-21 19:01:39.0000000,33.921127,-118.128477
2018-05-21 19:02:07.0000000,33.921125,-118.128454
2018-05-21 19:07:05.0000000,33.921274,-118.128355
2018-05-21 19:12:58.0000000,33.921248,-118.12841
2018-05-21 19:16:14.7281966,33.921248,-118.12841
2018-05-21 19:17:24.7289005,33.921248,-118.12841
2018-05-21 19:19:33.0000000,33.921268,-118.128418
2018-05-21 19:45:03.0000000,33.919818,-118.128749
2018-05-21 19:46:23.0000000,33.919817,-118.128748
2018-05-21 19:47:23.0000000,33.919754,-118.12907
2018-05-21 19:48:43.0000000,33.919703,-118.129382
2018-05-21 19:50:03.0000000,33.919585,-118.129189
2018-05-21 19:50:37.0000000,33.919383,-118.130163
2018-05-21 20:04:36.0000000,33.919789,-118.129882
2018-05-21 20:23:27.0000000,33.920036,-118.129822
2018-05-21 20:46:12.0000000,33.91993,-118.129499
2018-05-21 20:50:09.0062205,33.91993,-118.129499
2018-05-21 21:01:43.0000000,33.921195,-118.128403
2018-05-21 21:01:48.5683710,33.921195,-118.128403
2018-05-21 21:07:18.0000000,33.921135,-118.128448
2018-05-21 21:22:56.0000000,33.921089,-118.12849
2018-05-21 21:34:18.0000000,33.91897,-118.126026
2018-05-21 21:34:30.7203730,33.91897,-118.126026
2018-05-21 21:34:35.3922356,33.91897,-118.126026
2018-05-21 21:34:37.5172694,33.91897,-118.126026
2018-05-21 21:34:38.6891440,33.91897,-118.126026
2018-05-21 21:35:00.0000000,33.918843,-118.126122
2018-05-21 21:35:40.0000000,33.918683,-118.125967
2018-05-21 21:36:20.0000000,33.918748,-118.126087
2018-05-21 21:37:00.0000000,33.918762,-118.126094
2018-05-21 21:37:39.0000000,33.918776,-118.126102
2018-05-21 21:38:20.0000000,33.918772,-118.126098
2018-05-21 21:40:23.0000000,33.918516,-118.125526
2018-05-21 21:59:09.0000000,33.92636,-118.128706
И код, который я написал:
import pandas as pd
import reverse_geocoder as rg
import csv
source = pd.read_csv("Lookup.csv") # source file location
currentRow=0 # counts current row location
rowCount = source.shape[0] # queries number of rows
print(rowCount, "Rows total to be coded")
while currentRow < rowCount:
currentLat = source.iloc[currentRow, 1] # stores the current working latitude
currentLong = source.iloc[currentRow, 2] # stores the current working longitude
currentReportedTime = source.iloc[currentRow, 0] # stores the current reported time
Lat = currentLat
Long = currentLong
coordinates = (Lat, Long)
results = rg.search(coordinates,mode=1) # default mode = 2
print(results)
with open("results.csv", "a", newline='\n') as csv_file:
csv_app = csv.writer(csv_file)
csv_app.writerow([results, currentReportedTime])
currentRow = currentRow + 1
else:
print("Complete")
Любая помощь будет принята с благодарностью, спасибо!