import os
path = "C:/Users/username"
files = [file for file in os.listdir(path) if file.endswith(".tsv")]
for file in files:
df = pd.read_csv(os.path.join(path, file),
comment='#',
header=None,
sep='\t',
names=['index','count','text','tag'])
df.to_csv(os.path.join(path, file))
尝试使用
os
:注意:如您问题中所述,这将用修改的
df
覆盖现有文件我假设代码将在相同的数据文件夹中执行,请注意,您可以将
.
与glob.glob('.')
中的数据文件夹关联起来结果将保存在tmp文件夹中
相关问题 更多 >
编程相关推荐