Extending Power BI with Python and R by Luca Zavarella
Author:Luca Zavarella [Zavarella, Luca]
Language: eng
Format: epub
Tags: Power BI, Python, R, business intelligence, data visualization, dashboards, interactive visuals
Publisher: Packt Publishing
Published: 2021-11-26T00:00:00+00:00
From Figure 9.4, you can see that the resources node can contain more than one subnode, identified with an integer. This is because sometimes the geocoding engine cannot exactly identify the geographic point from the passed address and therefore returns more than one result. The estimatedTotal attribute indicates the number of possible geocodes identified. For simplicity, we have extracted from the JSON the last identified resource, which is the one with the highest identifier.
Besides the answer in JSON format, from the request, you can also extract other values, such as the reason for the state of the answer (useful to understand whether the GET operation is successful or not), the complete content of the answer in text format, and the URL used for the GET request. You will need the requests, urllib, json, pandas, and time modules. The latter is used to measure the geocoding execution time of all addresses in the dataset. Everything can be encapsulated in a handy function called bing_geocode_via_address():
def bing_geocode_via_address(address): # trim the string from leading and trailing spaces using strip full_url = f"{base_url}query={urllib.parse.quote(address.strip(), safe='')}?key={AUTH_KEY}" r = requests.get(full_url) try: data = r.json() # number of resources found, used as index to get # the latest resource num_resources = data['resourceSets'][0]['estimatedTotal'] formattedAddress = data['resourceSets'][0]['resources'][num_resources-1]['address']['formattedAddress'] lat = data['resourceSets'][0]['resources'][num_resources-1]['point']['coordinates'][0] lng = data['resourceSets'][0]['resources'][num_resources-1]['point']['coordinates'][1] except: num_resources = 0 formattedAddress = None lat = None lng = None text = r.text status = r.reason url = r.url return num_resources, formattedAddress, lat, lng, text, status, url
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Harry Potter and the Goblet Of Fire by J.K. Rowling(3040)
Never by Ken Follett(2878)
Shadow of Night by Deborah Harkness(2718)
Ogilvy on Advertising by David Ogilvy(2682)
Zero to IPO: Over $1 Trillion of Actionable Advice from the World's Most Successful Entrepreneurs by Frederic Kerrest(2388)
The Man Who Died Twice by Richard Osman(2297)
Machine Learning at Scale with H2O by Gregory Keys | David Whiting(2285)
Book of Life by Deborah Harkness(2263)
How Proust Can Change Your Life by Alain De Botton(2259)
My Brilliant Friend by Elena Ferrante(2221)
0041152001443424520 .pdf by Unknown(2219)
The Tipping Point by Malcolm Gladwell(2204)
How to Pay Zero Taxes, 2018 by Jeff A. Schnepper(2098)
Will by Will Smith(2040)
Purple Hibiscus by Chimamanda Ngozi Adichie(1981)
Hooked: A Dark, Contemporary Romance (Never After Series) by Emily McIntire(1954)
Borders by unknow(1785)
Rationality by Steven Pinker(1764)
Daughter of Smoke and Bone by Laini Taylor(1742)