-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
When I tried to pass in "DISTRICT" or "TOWN" as an argument into the api.locations() function, it cannot retrieve all of the districts as well as towns of each state. Below are outputs that I received when I call this function by passing "DISTRICT" and "TOWN" as arguments:
import cuaca
api = cuaca.WeatherAPI("YOUR_API_KEY")
districts = api.locations("DISTRICT")
df_district = pd.DataFrame(districts)
state_dct = {}
for lotrootid in df_district['locationrootid'].unique().tolist():
state_dct[lotrootid] = df_state['name'][int(lotrootid[-1]) - 1]
print(state_dct)
def swap_columns(df, col1, col2):
col_list = list(df.columns)
x, y = col_list.index(col1), col_list.index(col2)
col_list[y], col_list[x] = col_list[x], col_list[y]
df = df[col_list]
return df
df_district['locationrootid'] = df_district['locationrootid'].replace(state_dct)
df_district.rename(columns = {'locationrootid':'state'}, inplace = True)
df_district.drop(labels=['locationcategoryid'], axis=1, inplace=True)
df_district = swap_columns(df_district, 'id', 'state')
df_district_index = df_district.set_index(keys=['state', 'name', 'id', 'latitude', 'longitude'])#.swaplevel(0, 1)
df_district_index
towns = api.locations("TOWN")
df_towns = pd.DataFrame(towns)
df_towns['locationrootid'] = df_towns['locationrootid'].replace(state_dct)
df_towns.rename(columns = {'locationrootid':'state'}, inplace = True)
df_towns.drop(labels=['locationcategoryid'], axis=1, inplace=True)
df_towns = swap_columns(df_towns, 'id', 'state')
df_towns_index = df_towns.set_index(keys=['state', 'name', 'id', 'latitude', 'longitude'])#.swaplevel(0, 1)
df_towns_index
Metadata
Metadata
Assignees
Labels
No labels



