0

Similar to what's already posted here Create dataframe from two dictionaries. All keys are present in both dictionaries with the only difference being the shape of values that are arrays.

What I have:

d1 = {(1, "Autumn"): np.array([[2.5, 100], [4.5, 105], [7.5, 120], [9.5,137]]), (1, "Spring"): np.array([[10.5, 146], [11.7, 151], 
      [12.3, 164], [15.0, 173]])}
d2 = {(1, "Autumn"): np.array([10.2, 13.3, 15.7, 18.8]), (1, "Spring"): np.array([15.6, 20, 23, 27])}

What is to be achieved:

d3 = {(1, "Autumn"): pd.DataFrame([[2.5, 100, 10.2], [4.5, 105, 13.3], [7.5, 120, 15.7], [9.5, 137, 18.8]], 
      columns = ["x", "y", "z"]), (1, "Spring"): pd.DataFrame([[10.5, 146, 15.6], [11.7, 151, 20], [12.3, 164, 23], [15.0, 173, 27]],
                columns = ["x", "y", "z"])}

Can you please help me out? I tried using the approach posted as answer. However, I get ValueError: could not broadcast input array from shape (4,2) into shape (4) error.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
PratikSharma
  • 321
  • 2
  • 17
  • Are you trying to create a `dataframe` or a `dictionary`? Also, can you tell us **what** the output looks like instead of **how** to create it – Mortz Jan 07 '19 at 14:15
  • please see "what is to be achieved". I'm looking for dictionary of dataframes. – PratikSharma Jan 07 '19 at 14:25
  • Please change the title of your question - it says `create dataframe from dictionaries`. Also, I just copied your code and it works fine for me. What version of Pandas and Python are you using? – Mortz Jan 07 '19 at 14:34

0 Answers0