1

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.

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.

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
Chris
  • 1,401
  • 4
  • 17
  • 28
  • store them in a `dict`? – gold_cy Feb 02 '19 at 04:15
  • This is the second time. Please use a dictionary. – cs95 Feb 02 '19 at 04:15
  • If you're unable to use a dictionary, please clearly explain why... – cs95 Feb 02 '19 at 04:16
  • because I don't have the variable names, hence the keys. a, b and c are all lists, and var a list of lists. additionally, it feels like there should be a cleaner way to do this than simply creating another variable from which I pull variable names to save to. – Chris Feb 02 '19 at 04:21
  • sounds to me like you need a better way to approach your problem then, you should n't have to be dynamically creating the variable name itself – gold_cy Feb 02 '19 at 04:30
  • can you propose one? I'm doing the same tasks on a collection of JSONs with different names. post-processing I want to save the cleaned df to a different variable. I don't see any way around dynamic variable names given this – Chris Feb 02 '19 at 04:33

0 Answers0