Trying to figure out the code to remove the rows in csv file where in column Date there is date starting with 202110 (and any day). So all rows from October should be removed. Then I want to save csv with orginal name + 'updated'. I think that both part where I am trying to remove row is incorrect and save the file. Could you help?
My current code is
import os
import glob
import pandas as pd
from pathlib import Path
sourcefiles = source_files = sorted(Path(r'/Users/path/path/path').glob('*.csv'))
for file in sourcefiles:
df = pd.read_csv(file)
df2 = df[~df.Date.str.contains('202110')]
df2.to_csv("Updated.csv") # How to save with orginal file name + word "updated"
Just to give the example of csv file. As you can see in yellow highlighted cells there are dates in October, these rows I need to remove and save csv with 'updated' in name. Thanks a lot for help.