I'm working on Python 3.x. What is to be achieved is: merge dictionaries based on keys and form a dataframe. This would clear:
What I have:
import numpy as np
import pandas as pd
d1 = {(1, "Autumn"): np.array([2.5, 4.5, 7.5, 9.5]), (1, "Spring"): np.array([10.5, 11.7, 12.3, 15.0])}
d2 = {(1, "Autumn"): np.array([10.2, 13.3, 15.7, 18.8]), (1, "Spring"): np.array([15.6, 20, 23, 27])}
What I want to achieve:
d3 = {(1, "Autumn"): pd.DataFrame([[2.5, 10.2], [4.5, 13.3], [7.5, 15.7], [9.5, 18.8]],
columns = ["d1", "d2"]), (1, "Spring"): pd.DataFrame([[10.5, 15.6], [11.7, 20],
[12.3, 23], [15.0, 27]], columns = ["d1", "d2"])}
P. S.: I'm actually working on RandomForestRegressor
example. The above dictionaries are my X and y values after the train and test data splits. What I'm trying to achieve is to get X, y side-by-side in a dataframe for plots with above query. The size of dictionary is same as are the key and number of values for each key in both dictionaries.