May-06-2022, 07:15 PM
I have the following code that im using to open a CSV and then create a new filtered csv for importing into excel.
In the 3rd column of the file ("Comment") there is a value for each record that has 2 different values based on the row, so just need to replace this string:
Currently we open the file in NotePad++ and just do a find and replace, but would love to have that built into the creation of the new file so we dont have to remember to do that step.
# THIS OPENS THE NEWLY CLEAN DATA IN ORDER TO REMOVE OLD RECORDS df = pd.read_csv("Dates.txt", usecols=range(3), header=None, names=["Date", "Time", "Comment"]) # THIS CONVERTS THE DATE COLUMN INTO A DATETIME FORMAT df['DT'] = pd.to_datetime(df['Date'] + ' ' + df['Time']) # HERE YOU NEED TO PROVIDE THE DATE YOU WANT TO KEEP GOING FORWARD mask = (df['DT'] > '2022-04-28 7:06 AM') # THIS RETURNS ALL ROWS GREATER THAN THE DATE PROVIDED ABOVE ndf = df.loc[mask]The above works great and does what is needed, NOW we are trying to do a mass replace for a key string value so that it can update the pivot table we have in excel when the data is imported.
In the 3rd column of the file ("Comment") there is a value for each record that has 2 different values based on the row, so just need to replace this string:
Someone Else: with Completed:And replace this string:
Davids: with Dave:Is it possible to do a find and replace or do we have to do it per line?
Currently we open the file in NotePad++ and just do a find and replace, but would love to have that built into the creation of the new file so we dont have to remember to do that step.