Python Forum
Pands DataFrame merge question - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Pands DataFrame merge question (/thread-12957.html)



Pands DataFrame merge question - FORTITUDE - Sep-20-2018

Hi,

I am learning Python and trying to combine two DataFrame together which has same Index and columns.

So I have two DataFrame A and B

DataFrame A has following setup
Output:
COMPANY SHARE EOD PRICE -------------------------------- SONY 10 7 APPLE 20 5 GOOGLE 30 10
while DataFrame B has following setup
Output:
COMPANY SHARE EOD PRICE -------------------------------- SONY 60 7 APPLE 40 9
Assume I am trading these stocks using Broker A (DataFrame A) and Broker B (DataFrame B). I want to consolidate my total traded shares in one table. The end of day price for all the stock should be the same even traded in different company. However, there are some exceptions which Company A may have different price than Company B. In this case I trust Company A better so if they have different price on same stock then I would stick to A. In the same time I want to consolidate (aggregate) all my traded shares together.

So I expect the result/output will look like
Output:
COMPANY SHARE EOD PRICE -------------------------------- SONY 70 7 APPLE 60 5 GOOGLE 30 10
SO Good data (e.g. SONY and GOOGLE here) has same price and merge function can help me to sum up the share.

But the exception here is price for APPLE is different between DF A and DF B but I want to use Price in DF A whenever there is discrepancies.

What's the most efficient DataFrame code to achieve this?

Thanks,

Allen