匯入位址excel,抓取相應地區的經緯度

2021-10-08 22:01:35 字數 1386 閱讀 1171

匯入excel對應的位址,抓取相應地區的經緯度

import requests

import pandas as pd

import numpy as np

import copy

import json

area = pd.read_excel(r'c:\users\mei\desktop\area\area.xlsx')

# 插入列儲存經緯度 列數有city變成city,經緯度

col_name = area.columns.tolist()

index1, index2 = col_name.index('city') + 1, col_name.index('city') + 2

col_name.insert(index1, '經度')

area = area.reindex(columns = col_name)

col_name.insert(index2, '緯度')

# area.iloc[0,1] = 2.34

area = area.reindex(columns = col_name)

l = len(area)

def geocodeb(address):

# base = "" + address + "&output=json&key=fxoixu7hfbwmjygxgm6kubby7nc2egzg"

base = "" + address + "&output=json&ak=fxoixu7hfbwmjygxgm6kubby7nc2egzg"

response = requests.get(base)

answer = response.json()

return answer['result']['location']['lng'],answer['result']['location']['lat']

# geocodeb('廣州市')

area_a = copy.copy(area)

lng =

lat =

for i in range(l):

list1 = list(geocodeb(area.iloc[i,0]))

# print(area_a.iloc[i, 1])

#area_a.iloc[i, 1] = a

#area_a.iloc[i, 2] = b

area_a['經度'] = lng

area_a['緯度'] = lat

# print(area_a)

area_a.to_excel(r'c:\users\mei\desktop\area\area_result.xlsx', index=false) #輸出經緯度資訊

pycharm直接匯入相應的庫

游標放在下面有紅槓槓的地方,然後按alt enter鍵,選庫參考 最近做了python飛機大戰的專案,有一點點感慨,感覺 不會寫可能是這樣的 有些函式掌握還是不夠,python中很多方便的函式可以給大家使用,而且他的for迴圈的效率是明顯沒有c c 中高的,還是盡量使用現成的函式。但這些函式怎麼去發...

excel表的匯入

判斷匯入資訊是否與dw視窗中資訊重複 int n for n 1 to dw 1.rowcount string ls llk int ls count ls llk dw 1.getitemstring n,1 select count into ls count from cliendservi...

Excel的匯入功能

專案中使用到了excel的匯入功能,趕了兩天終於可以跑起來了,下面寫下實現的具體思路 大家都知道,poi是很好用的讀取excel檔案的技術,而且只需匯入乙個jar檔案即可,非常的方便 學習起來也特別的容易,網上這方面的資料非常多。具體的應用網上都有現成的demo。其實要是技術上的難點,應該算是也實現...