Skip to content
Advertisement

Merging 2 different DataFrame with different length

I have two DataFrame Consists of time and price columns.

JavaScript

I want to create a new DataFrame df3 as the length of df2, and I also want to put df1[‘price’] in it like below

JavaScript

Where price1 shows the mean of price1 values for the corresponding time2 values like below

JavaScript
JavaScript

I’m sorry if it’s unclear, but could you advise me on how to do the above cleanly?

Thank you very much.

Advertisement

Answer

you can try data frame merge with inner join. following would be logic you can work with! comment section gives more insight on code.

JavaScript

now merge will do the job:

JavaScript

enter image description here

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