I am trying to build a master DataFrame over time. Lets say its imported from a csv file and looks something like this:
df = pd.DataFrame(columns=['col1', 'col2', 'col3', 'col4']).rename_axis='Date'
At some point in time I will have a DataFrame like this, that I will append to df.
dfb = pd.DataFrame(columns=['col1', 'col2']).rename_axis('Date')
At a later point in time I will have another DataFrame, call it dfe, containing the remaiming col3 and col4.
dfe = pd.DataFrame(columns=['col3', 'col4']).rename_axis('Date')
How do I add dfe to df such that it fills in on the same row and does not generate additional columns. I tried:
df = pd.concat([df, dfe], axis=1)
but new columns are generated. I think this is because the previous append step put NaN
values in col3
and col4
.
UPDATE: I asked this in a somewhat different way and recieved great answers. See the post here.