Closed rebeccajohnson88 closed 3 years ago
Some var renaming code but it may not be the most useful --- basic idea is to use the acs_predictors csv which has both the formal varname and the description to rename the variables using a dictionary-- since some descriptions just say "total" it might be good to paste the following two columns together:
def df_column_uniquify(df):
df_columns = map(str.lower, df.columns)
new_columns = []
for item in df_columns:
counter = 0
newitem = item
while newitem in new_columns:
counter += 1
newitem = "{}_{}".format(item, counter)
print(newitem)
new_columns.append(newitem)
df.columns = new_columns
return df
census_varnames_dict_percent = census_varnames.set_index('variable_topull_sql').to_dict()['varnames_percent']
## rename data
percentages_rename = percentages_wide_pivot_reset.rename(columns = census_varnames_dict_percent)