python - Pandas: iteratively concatenate columns stored in a dictionary of dataframes -
suppose have dictionary of pandas dataframes keys 0, 1, 2, ..., 999, , values dataframes (test_df):
b c 0 1.438161 -0.210454 -1.983704 1 -0.283780 -0.371773 0.017580 2 0.552564 -0.610548 0.257276 3 1.931332 0.649179 -1.349062 4 1.656010 -1.373263 1.333079 5 0.944862 -0.657849 1.526811 say index means nothing you, , want create new dataframe columns a , b concatenated:
mydf=pd.concat([test_df[0]['a'],test_df[0]['b']], axis=1, keys=['a','b'])
now, can use line inside loop iterates on keys in dictionary of dataframes?
if not, way of doing this? result dataframe 2 columns, a , b, , 6x1000 rows. index column therefore go 0 5999.
if df_dic dictionary, can do:
pd.concat([df[['a', 'b']] df in df_dic.values()]).reset_index(drop=true) here result looks if df_dic contains 2 key-value pairs:

Comments
Post a Comment