这本词典:
左侧:IAO,INOT_A
等是数据框,右侧是列。
dict1 =({'IAO' : ['N','OBD'] ,'INOT_A' : ['CIN','OTID'],
'IA_PST_S' : ['K','OBD'], 'IA' : ['K','jse']})
此代码使df
在最后一行(问题)的每个循环中都被替换:
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]]
如何使其存储在其他df中?
答案 0 :(得分:4)
您可以使用原始dict1
的键创建DataFrame字典:
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
然后选择每个DataFrame
使用:
print (dfs['IAO'])