I have a directory (with several subfolders) of csv files. I want to delete the first 2 rows of all csv files before I upload the csv files to a database (SQL server). I started with the following python script on a small subset of csv files located in one folder (no sub folders) and although the script runs successfully but no rows are deleted from the files. What am I missing:
import glob import csv myfiles = glob.glob("C:\Data\*.csv") for file in myfiles: lines = open(file).readlines() open(file, 'w').writelines(lines[1:]) Here is my sample data:
"Title: Distribution of Nonelderly Population by Household Employment Status | The Henry J. Kaiser Family Foundation" "Timeframe: 2015" "Location","At Least 1 Full Time Worker","Part Time Workers","Non Workers","Total" "United States","0.82","0.08","0.10","1.00" "Alabama","0.79","0.06","0.15","1.00" "Alaska","0.85","0.06","0.09","1.00" "Arizona","0.80","0.08","0.12","1.00" "Arkansas","0.78","0.07","0.15","1.00" "California","0.81","0.08","0.10","1.00" I want to maintain the same directory structure with the edited output csv files. Any help will be highly appreciated.
os.walk