1
votes

I am using datacompy to compare data in 2 excel files. I would like to send the output to an excel file (possibly an email too but that's not the priority ). How can I do that ?

I have tried storing the value of compare.report and passing that to the excel though it doesn't work

compare = datacompy.Compare(df1,df2,join_columns=['COL_A','COL_B']) compare_rep = compare.report()

with pd.ExcelWriter('Comparison_report.xlsx') as writer: compare_rep.to_excel(writer,sheet_name = 'DM',index=False)

2

2 Answers

0
votes

You are trying to write a string to an excel file (which is not possible with pd.DataFrame.to_excel()) since compare.report() does not produce a Dataframe.

print(type(compare_rep))
<class 'str'>

Refer to this link for more info.

0
votes

You can split the String line by line into a list and write it to excel in case if you are using OpenPyxl.

Similarly, if you want to email the report you can use SMTPLIB

import smtplib
server = smtplib.SMTP('smtp.gmail.com', 587)

#Next, log in to the server
server.login("youremailusername", "yourpassword")

#Send the mail
#compare.report() is the datacompy report string
server.sendmail("[email protected]", "[email protected]", compare.report())