<jupyter_start><jupyter_text>Segmenting and Clustering Neighborhoods in Bangalore City<jupyter_code>import pandas as pd
import numpy as np
import requests
import time
df = pd.read_csv("all_india_PO_list_without_APS_offices_ver2_lat_long.csv")
df.info()
df.head()
df = df[["pincode", "officename", "Districtname", "regionname"]]
df.head()
df.dropna(inplace=True)
df.info()
bng_df = df[df.regionname.str.contains("Bangalore")].reset_index(drop=True)
bng_df.head()
bng_df.shape
def geocode(postalcode):
    API_KEY = '<KEY>'
    url = 'https://us1.locationiq.com/v1/search.php'
    params = {'key': API_KEY, 'format':'json', 'postalcode':postalcode}
    r = requests.get(url, params=params)
    result = r.json()
    time.sleep(1) # Only 60 requests are allowed per minute so delaying each request by sec 
    print((result[0]['lat'], result[0]['lon']))
    return (result[0]['lat'], result[0]['lon'])
# bng_df['Latitude'] = bng_df['Postcode'].apply(lambda x: geocode(x)[0])
lat = []
lng = []

def lat_lng_list_gen(postalcode):
    lat_lng = geocode(postalcode)
    lat.append(lat_lng[0])
    lng.append(lat_lng[1])
bng_df['pincode'].apply(lambda x: lat_lng_list_gen(x))
bng_df['Latitude'] = lat
bng_df['Longtude'] = lng
bng_df.head()
bng_df.to_csv("bangalore.csv", index=False)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.167816091954023, 'fraction_numerical': 0.00996168582375479, 'mean_word_length': 6.059459459459459, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '526099', 'license': 'MIT', 'n_tokens_mistral': 527, 'n_tokens_neox': 513, 'n_words': 91, 'path': 'prepare_bangalore_dataset.ipynb', 'repo_name': 'albertechin/Coursera_Capstone', 'size': '1314'}