1

I am reading the csv data to a data frame, after that the python code is performing some updates in the data frame. On printing the data frame I can see the updated values, but on writing back to the csv. I am still getting the old values.

to_csv is not writing the updated DataFrame

The issue is similar to the above link, but I just have a single class code with no multiple reference to the same file, still I am getting the same issue and I do not have enough reputation to comment on that post.

import win32com.client as win32
import pandas as pd



class MailDispatcher:

    global file_location
    file_location = 'C:\Pilot Run\Files\\'

    delivery_status = pd.read_csv(file_location + "delivery_status.csv")

    for index, row in delivery_status.iterrows():

        # Mail trigger
        outlook = win32.Dispatch('outlook.application')
        mail = outlook.CreateItem(0)
        mail.To = 'abc@gmail.com'
        mail.Subject = 'test ' + str(row[3])

        if mail.Send() is None:
            row[4] = 'Y'
            print(row) #printing correct data
            outlook.Quit()

    print(delivery_status)
    #output = open(file_location + 'delivery_status.csv', 'w')

# writing old data in csv
    delivery_status.to_csv(file_location + 'delivery_status.csv', index=None, header=True)
    #output.close()

##Tried with the below code to as per some comments, still getting the same issue:

    output = open(file_location + 'delivery_status.csv', 'w')
    delivery_status.to_csv(output, index=None, header=True)
    output.close()
Dip Chatterjee
  • 87
  • 2
  • 12

0 Answers0