I have different data frames and I need to combine them based on a date column. If I only had two data frames, I could use df1.merge(df2, on='date') to do this with three data frames, I would use df1.merge(df2.merge(df3, on='date'), on='date') , however it becomes really complex and unreadable to do this with multiple data frames.
All data frames have one common column - date , but they do not have the same number of rows and columns, and I need only those rows in which each date is common for each data frame.
So, I'm trying to write a recursive function that returns a data frame with all the data, but that didn't work. How then to combine several data frames?
I tried in many ways and got errors like out of range , keyerror 0/1/2/3 and can not merge DataFrame with instance of type <class 'NoneType'> .
This is the script I wrote:
dfs = [df1, df2, df3]
Example: df_1:
May 19, 2017;1,200.00;0.1% May 18, 2017;1,100.00;0.1% May 17, 2017;1,000.00;0.1% May 15, 2017;1,901.00;0.1%
df_2:
May 20, 2017;2,200.00;1000000;0.2% May 18, 2017;2,100.00;1590000;0.2% May 16, 2017;2,000.00;1230000;0.2% May 15, 2017;2,902.00;1000000;0.2%
df_3:
May 21, 2017;3,200.00;2000000;0.3% May 17, 2017;3,100.00;2590000;0.3% May 16, 2017;3,000.00;2230000;0.3% May 15, 2017;3,903.00;2000000;0.3%
Expected Merger Result:
May 15, 2017; 1,901.00;0.1%; 2,902.00;1000000;0.2%; 3,903.00;2000000;0.3%