Файлы выглядят так:
Код: Выделить всё
Bunch of useless lines
DataName A B C D
DataValues 1 2 3 4
....
Other bunch of uselsess lines
РЕДАКТИРОВАТЬ
После нескольких часов, потраченных на это, я смог придумать что-то вроде этого:
Код: Выделить всё
for dirpath, dirnames, filenames in os.walk(path):
for file in filenames:
print(file)
if file.lower().endswith('.csv'):
start = file.index('_ ')
end = file.rindex(' (')
xy = file[start + 1:end]
x = xy.split()[0]
y = xy.split()[1]
to_skip = []
with open(os.path.join(dirpath, file), 'r') as fin:
for index, line in enumerate(fin):
if line[0:4] != 'Data':
to_skip.append(index)
print(to_skip)
data = pd.read_csv(os.path.join(dirpath, file),
skiprows=to_skip,skip_blank_lines=True,
on_bad_lines='skip',index_col=False,
skipinitialspace=True)
Подробнее здесь: https://stackoverflow.com/questions/793 ... evant-data
Мобильная версия