Python Forum
How to use pandas to compare two DataFrames having different structure
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use pandas to compare two DataFrames having different structure
#1
hi all
Please accept my apologies if this is not the correct forum for pandas.,
I am a new python pandas user and have a question.

I have two DataFrames as follows
df1 = pd.read_excel('TR_TRAUS_contacts.xlsx', index_col=0, dtype={'Name': str,'Market': str, 'Class': str,
'First Name': str, 'Last Name': str, 'Job Title': str, 'Email': str, 'Phone Number': str, 'Mobile Number': str, 'Street Address': str, 'City': str, 'State': str, 'Post Code': str})

df2 = pd.read_csv('Customers.csv', index_col = 0, dtype={'Name': str, 'Status': str, 'Currency':str, 'PaymentTerm': str, 'TaxRule': str, 'AccountReceivable': str, 'SaleAccount': str, 'PriceTier': str, 'Discount': str, 'CreditLimit': str, 'Carrier': str, 'SalesRepresentative': str, 'Location': str, 'TaxNumber': str, 'Tags': str, 'AttributeSet': str, 'AdditionalAttribute1': str, 'AdditionalAttribute2': str, 'AdditionalAttribute3':str, 'AdditionalAttribute4': str, 'AdditionalAttribute5': str, 'AdditionalAttribute6': str, 'AdditionalAttribute7': str, 'AdditionalAttribute8': str, 'AdditionalAttribute9': str, 'AdditionalAttribute10': str, 'Comments': str, 'ContactName': str, 'JobTitle': str, 'Phone': str, 'MobilePhone': str, 'Fax': str, 'Email': str, 'Website': str, 'ContactComment': str, 'ContactDefault': str, 'ContactIncludeInEmail': str, 'IsAccountingDimensionEnabled': str})

df1 and df2 columns are differenct
df2 and df12 columns are the same

I need to generate df12 (.csv) with some column values extracted from df1 based on a condition that only rows that exist in df1 but are inexistent in df2.
Index 'Name' colum exists in both df1 and df2

note:
I have achieved above using JavaScript[Image: df1.jpg][Image: df1df2df12.jpg] on Google Sheets, via iteration.
I have been told not to use Iteration in Pandas

thanks in advance for any help

Attached Files

Thumbnail(s)
               
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,911 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 4,319 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  Database table structure compare(Oracle) GKT 4 2,826 Oct-16-2019, 03:16 PM
Last Post: GKT

Forum Jump:

User Panel Messages

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