I am trying to skip the first 23 lines of a txt file and read the data from line 24 onwards. The script itself worked fine before the file types changed and now I need to skip the first 23 rows of text.
I have tried two ways:
with open("D:\\Annette testing from 19 May onwards\\30cm", "*.txt",'r') as f:
lines_after_23 = f.readlines()[23:]
with open("D:\\Annette testing from 19 May onwards\\30cm", "*.txt") as f:
for line in itertools.islice(f, 24, None):
but I can't get it to work... what am I doing wrong?
Original script (I need to add in the skipping of the rows to this script):
import os
import glob
from NAP_transform import transform
# %% importing and transforming all files
file_path = os.path.join("D:\\Annette testing from 19 May onwards\\30cm", "*.txt")
filenames = glob.glob(file_path)
# %% TRANSFORMING 0 DEGREE MEP NO NECK IMPACTS
# Processing each impact in the folder
for a in filenames:
print("Now processing:", a)
# Set the name for the impact
# impact_name = a.replace("D:\\Annette testing from 19 May onwards\\", "")
# impact_name = impact_name.replace("\\", " ") # Replace slash with spaces
impact_name = a.replace("txt", "csv") # Set as a csv file
# Transforming the data
data_out = transform(a, 2021)
# Setting the file path for the export files
# export_file_path = "D:\\Annette testing from 19 May onwards\\" + impact_name
# Creating and saving the full data file
data_out.to_csv(impact_name)