I have a collection of JSON variables, all with the same format and data irregularities, that I'd like to correct and then reassign to data frames for processing.
Since I'm doing performing the same process over and over, I'm just planning to run cleaning portion of the code as a for loop.
I'm getting stuck at the point, post-cleaning, that I have a generic dataframe, df, that I now want to assign to a permanent data frame before moving to the next variable.
Ideally, I'd simply call the exec()
function, appending the respective variable name to 'df_', but I'm not sure how to strip the variable name as a string from the variable itself, and I also understand this isn't very pythonic.
I've included the respective code below. With variable names [a, b, c], I'd like to assign df to a new data frame called df_a, df_b, and df_c respectively. Any ideas on how to do this.
vars = [a, b, c]
# clean data iteratively
for i in vars:
df = pd.DataFrame(i)
df['value'] = df['value'].replace('.', np.nan).fillna(method='bfill')
df['value'] = pd.to_numeric(df['value'])
[???] = df
edit: the linked question addresses something different than what I'm asking. I don't need the variable content, I need the variable name; additionally, I'm asking if there's a more pythonic way to do this...nothing in the linked question addresses this.