user51332
user51332

Reputation: 145

Make each result stored in a different dataframe?

This dictionary:

The left side: IAO,INOT_A,etc are dataframes and the right to them are the columns.

dict1 =({'IAO' :  ['N','OBD'] ,'INOT_A' : ['CIN','OTID'], 
          'IA_PST_S' : ['K','OBD'], 'IA' : ['K','jse']})

This code makes the df to be replaced in each loop in the last line (problem) :

for k, v in dict1.items():
    df = pd.DataFrame.from_records(data=arcpy.da.SearchCursor(k, v))
    df.columns = v
    column_for_count =v[0]
    df['count_of_' + column_for_count]=[df[column_for_count].value_counts().loc[x] for x in df[column_for_count]]

How to make it get stored in a different df?

Upvotes: 2

Views: 47

Answers (1)

jezrael
jezrael

Reputation: 862641

You can create dictionary of DataFrame, with keys by by original dict1:

dfs = {}
for k, v in dict1.items():
    df = pd.DataFrame.from_records(data=arcpy.da.SearchCursor(k, v))
    df.columns = v
    column_for_count =v[0]
    df['count_of_' + column_for_count]=[df[column_for_count].value_counts().loc[x] for x in df[column_for_count]]
    dfs[k] = df

Then for select each DataFrame use:

print (dfs['IAO'])

Upvotes: 4

Related Questions