python - Creating pandas dataframes within a loop -
i attempting create approximately 120 data frames based upon list of files , dataframe names. problem after loop works, dataframes don't persist. code can found below. know why may not working?
for fname, dfname in zip(csv_files, df_names): filepath = find(fname, path) dfname = pd.dataframe.from_csv(filepath)
this python feature. see simpler example: (comments show outputs)
values = [1,2,3] v in values: print v, # 1 2 3 v in values: v = 4 print v, # 4 4 4 print values # [1, 2, 3] # values have not been modified
also @ question , answer: modifying list iterator in python not allowed?
the solution suggestd in comment should work better because not modify iterator. if need name access dataframe, can use dictionanry:
dfs = {} fname, dfname in zip(csv_files, df_names): filepath = find(fname, path) df = pd.dataframe.from_csv(filepath) dfs[dfname] = df print dfs[df_names[1]]
Comments
Post a Comment