I have 2 lists of several one element dictionaries each. The dictionaries have a string as key and a DataFrame as value. The keys are not sorted alphabetically within the lists. My goal is to perform pandas join function on the DataFrames in each list corresponding to each dictionary key.
Schematically:
import pandas as pd
import numpy as np
a = pd.DataFrame(np.random.randn(4, 4), columns=['h', 'i', 'j', 'k'])
b = pd.DataFrame(np.random.randn(4, 4), columns=['h', 'i', 'j', 'k'])
c = pd.DataFrame(np.random.randn(4, 4), columns=['h', 'i', 'j', 'k'])
d = pd.DataFrame(np.random.randn(4, 4), columns=['h', 'i', 'j', 'k'])
e = pd.DataFrame(np.random.randn(4, 4), columns=['n', 'o', 'p', 'q'])
f = pd.DataFrame(np.random.randn(4, 4), columns=['n', 'o', 'p', 'q'])
g = pd.DataFrame(np.random.randn(4, 4), columns=['n', 'o', 'p', 'q'])
h = pd.DataFrame(np.random.randn(4, 4), columns=['n', 'o', 'p', 'q'])
d1 = {'m':a}
d2 = {'h':b}
d3 = {'z':c}
d4 = {'b':d}
d5 = {'z':e}
d6 = {'h':f}
d7 = {'m':g}
d8 = {'b':h}
l1 = [d1, d2, d3, d4]
l2 = [d5, d6, d7, d8]
My goal is to join the DataFrames which have a corresponding key on each list, through a loop, in order to have the code matching the keys, ideally:
d1.join(d7)
d2.join(d6)
d3.join(d5)
d4.join(d8)
I cannot find a way to figure out the code to do this. Thanks for any help in advance!