0

I have an Ordered Dictionary, where the keys are the worksheet names, and the values contain the the worksheet items. Thus, the question: How do I use each of the keys and convert to an individual dataframe?

import pandas as pd
powerbipath = 'PowerBI_Ingestion.xlsx' dfs = pd.read_excel(powerbipath, None)

values=[] for idx, eachdf in enumerate(dfs):
    eachdf=dfs[eachdf]
    new_list1.append(eachdf)
    eachdf = pd.DataFrame(new_list1[idx])

Examples I have seen only show how to convert from an ordered dictionary to 1 pandas dataframe. I want to convert to multiple dataframes. Thus, if there are 5 keys, there will be 5 dataframes.

BrianBeing
  • 431
  • 2
  • 4
  • 12

2 Answers2

1

You may want to do something like this, (Assuming your dictionary looks like 'd') :

d = {'first': [1, 2], 'second': [3, 4]}
for i in d:
  df = pd.DataFrame(d.get(i), columns=[i])
  print(df)

Output looks like :

   first
0      1
1      2
   second
0       3
1       4
Snehaa Ganesan
  • 509
  • 3
  • 10
0

Here is a basic answer using one of these ideas

keys = df["key_column"].unique
df_array = {}
for k in keys : 
   df_array[k] = dfs[dfs['key_column'] == k]

There might be more efficient way to do it though.

Nakeuh
  • 1,757
  • 3
  • 26
  • 65