Reputation: 121
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)
Upvotes: 1
Views: 1836
Reputation: 21
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())
Upvotes: 0