Python 反向地理编码在循环运行时失败
我一直在尝试反向地理编码和提取pincodes。.csv文件有大约100万条记录 下面是我的问题Python 反向地理编码在循环运行时失败,python,geocoding,Python,Geocoding,我一直在尝试反向地理编码和提取pincodes。.csv文件有大约100万条记录 下面是我的问题 1. Google API failing to give address for large records, and taking huge amount of time. I will later move it to Batch-Process though. 2. I tried to split the file into chunks and ran few files manuall
1. Google API failing to give address for large records, and taking huge amount of time. I will later move it to Batch-Process though.
2. I tried to split the file into chunks and ran few files manually one by one (1000 records in each file after splitting), then i surprisingly get 100% result.
3. Later, I ran in loop one by one, again, Google API fails to give the result
注意:现在我们正在寻找免费API的唯一
**Below is my code**
def reverse_geocode(latlng):
result = {}
url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng={}'
request = url.format(latlng)
key= '&key=' + api_key
request = request + key
data = requests.get(request).json()
if len(data['results']) > 0:
result = data['results'][0]
return result
def parse_postal_code(geocode_data):
if (not geocode_data is None) and ('formatted_address' in geocode_data):
for component in geocode_data['address_components']:
if 'postal_code' in component['types']:
return component['short_name']
return None
dfinal = pd.DataFrame(columns=colnames)
dmiss = pd.DataFrame(columns=colnames)
for fl in files:
df = pd.read_csv(fl)
print ('Processing file : ' + fl[36:])
df['geocode_data'] = ''
df['Pincode'] = ''
df['geocode_data']=df['latlng'].map(reverse_geocode)
df['Pincode'] = df['geocode_data'].map(parse_postal_code)
if (len(df[df['Pincode'].isnull()]) > 0):
d0=df[df['Pincode'].isnull()]
print("Missing Picodes : " + str(len(df[df['Pincode'].isnull()])) + " / " + str(len(df)))
dmiss.append(d0)
d0=df[~df['Pincode'].isnull()]
dfinal.append(d0)
else:
dfinal.append(df)
有人能帮我吗?我的代码有什么问题?或者,如果需要任何其他信息,请让我知道……您遇到了谷歌API的使用限制。没错。。我必须中断调用函数以检查。。。并得到“时间限制错误”。。谢谢欧文!!!