Python Forum
Pands DataFrame merge question
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pands DataFrame merge question
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Question on pandas.dataframe merging two colums shomikc 4 783 Jun-29-2023, 11:30 AM
Last Post: snippsat
Question How can I merge several images via loop using the information of a dataframe? noahverner1995 1 1,399 Dec-31-2021, 05:03 AM
Last Post: noahverner1995
  Mail Merge from DataFrame into Word Label Template PEGylated_User 0 1,915 Nov-10-2020, 01:01 PM
Last Post: PEGylated_User
  Newbie question to use lambda on multiple columns of a dataframe zydjohn 0 5,789 Jan-23-2018, 06:08 PM
Last Post: zydjohn
  Newbie question to add columns in dataframe zydjohn 1 2,631 Dec-24-2017, 05:49 PM
Last Post: ODIS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020