'Convert multiple files from tsv to csv using pandas and glob
While trying to convert the tab separated files (.tsv extension) to comma separated files (.csv extension) from local folder, it converted first two files to .csv but the last 2 files are not converted to .csv.
Here is list of files format :
dir--
abc.tsv
red 1.tsv
yellow 2022.01.20.tsv
blue 2022.01.28.tsv
for the first 2 files will be converting into .csv as successfully. But last 2 files are not being converted as .csv and it's throwing the error like :
ValueError: Excel file format cannot be determined, you must specify an engine manually.
Here is the sample code snippet :
import glob
import pandas as pd
tsvfiles =
glob.glob('C:/Users/xxxx/xxx/xxx/*.tsv')
for tsv_file in tsvfiles:
out = tsv_file.split('.')[0]+'.csv'
df = pd.read_csv(tsv_file)
df.to_csv(out)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
