Skip to content
Advertisement

How to set merge and normalize multple dataframes for pd.merge_as_of

I am trying to merge multiple dataframes using pd.merge_asof.

They all contain 2 columns with datetime as index column and a variable column with floating values. They are not balanced in their indexes and times so I have to normalize the values.

JavaScript
JavaScript

I can succesfully merge the dfs and normalize the values like this using

JavaScript
JavaScript

Now what I want to do is to merge more than 2 dataframes. I tried doing this:

JavaScript

but I am getting the error

JavaScript

I am not sure what it is indicating. I removed the one of the index arguments and it still said the same thing. Any way I can get what I need to do?

I want to be able to append dataframe3 which has value3 column to the right of value2 column.

Advertisement

Answer

According to the documentation, merge_asof can only accept two dataframes, the error is caused because in the third argument of the function it expects some other parameter. As @Quang Hoang mentions you can use the reduce function to apply a two-parameter function cumulatively. The way in your case would be:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement