def state_zip_by_popdense(state_str, num_returns): search = SearchEngine() res = search.query(state=state_str, sort_by=Zipcode.population_density, ascending=False, returns=num_returns) return [x.zipcode for x in res]
def get_zipcode_of_richest_near_city(lat, lng): search = SearchEngine(simple_zipcode=True) zip = [] radius = 25 res = search.query(lat=lat, lng=lng, radius=radius, sort_by=Zipcode.median_household_income, ascending=True, returns=25) for i in res: zip.append(i.zipcode) return zip
def get_zipcode_of_richest_near_city(lat, lng): search = SearchEngine(simple_zipcode=True) zip=[] radius = 100 res = search.query( lat=lat, lng=lng, radius=radius, sort_by=Zipcode.median_household_income, ascending=False, returns=100, ) print(res) for i in res: zip.append(str(i.median_household_income) + " " + i.major_city) return zip
def get_city_data(): city_zip = [] for i in range(0, zip_dem.shape[0]): search = SearchEngine(simple_zipcode=False) res = search.query(city=zip_dem['major_city'][i], state=zip_dem['state'][i], returns=100) for zipcode in res: city_zip.append(zipcode.zipcode) city_data = pd.DataFrame() for i in city_zip: zipcode = search.by_zipcode(i) table = json_normalize(json.loads(zipcode.to_json())) city_data = pd.concat([city_data, table], axis=0) city_data = city_data.reset_index(drop=True) city_data.dropna(inplace=True) city_data = city_data.replace({None: np.nan}) city_data = city_data.reset_index(drop=True) return city_data