我有一个数百个CSV的文件夹,我需要将其转换为TSV以进行Postgres上传。
我写了这个脚本,但是运行它似乎什么也没发生。谁能看到问题所在?
import os
import sys
import csv
import pandas as pd
import numpy as np
import pathlib
for file in pathlib.Path().rglob('*.csv'):
with open(file,'r') as csvin, open(file + ".tsv", 'w') as tsvout:
csvin = csv.reader(csvin)
tsvout = csv.writer(tsvout, delimiter='\t')
for row in csvin:
tsvout.writerow(row)
答案 0 :(得分:0)
您正在导入熊猫...您可以尝试:
import os
import sys
import csv
import pandas as pd
import numpy as np
import pathlib
for file in pathlib.Path().rglob('*.csv'):
df = pd.from_csv(str(file))
df.to_csv(str(file.with_name(file.stem + ‘.csv’)), sep=‘\t’)