我正在尝试在 python 脚本中将多个 csv 文件组合成 1 个 csv 文件。我想跳过编写每个 csv 文件的前 5 行。遇到一些麻烦,我是 Python 新手。我尝试了几个我发现的示例,但工作目录似乎有问题。这是我最近的尝试:
import pandas as pd
import csv
import glob
import os
path = '//server01/tmp/'
files_in_dir = [f for f in os.listdir(path) if f.endswith('csv')]
count = 0
for filenames in files_in_dir:
df = pd.read_csv(filenames)
if count < 6:
count += 1
continue
df.to_csv('out.csv', mode='a')
任何帮助,将不胜感激。谢谢!