I've looked through old questions and they solve similar problems but not the one I'm trying to figure out. As quick background, I'm ingesting an API that sometimes returns slightly different objects, but I'd like to append them all to the same table.
If the value is not in one of the dictionaries I'd like for that to be left blank in the dataframe
df = pd.DataFrame(columns=['C1','C2','C3','C4'])
r1 = {'C1':20,'C2':15,'C3':10,'C4':53}
r2 = {'C1':47,'C3':26,'C4':17}
r3 = {'C2':31,'C3':64,'C4':29}
r4 = {'C1':64,'C2':17}
r5 = {'C1':45,'C2':24,'C3':71,'C4':63}
How do I loop over r1-5 and append them to the DataFrame like this?
C1 C2 C3 C4
20 15 10 53
47 None 26 17
None 31 64 26
64 17 None None
45 24 71 63
Thanks in advance!
EDIT: To add some additional information, here's something I've tried so far.
I've turned each dictionary into a list of dictionaries and then tried to loop over each of those key:value pairs and use the Key in the Loc function
As an example:
r1 = [{'C1':20},{'C2':15},{'C3':10},{'C4':53}]