Suppose you have a CVS file with consecutive filenames like this:
The character code of the original file is Shift-JIS, and these are converted to UTF-8 at once. Furthermore, the serial numbers of the files are eliminated from zero padding and renamed as follows:
The code is as follows.
ChangeShiftJIS2utf8.ipynb
import csv
import codecs
a = 47
for i in range(a):
pref = i + 1
path = "c:/*****/brabra_%02.f.csv"%pref
path_utf = "C:/****/brabra_%01.f_utf.csv"%pref
fin = codecs.open(path, "r", "shift_jis")
fout_utf = codecs.open(path_utf, "w", "utf-8")
for row in fin:
fout_utf.write(row)
fin.close()
fout_utf.close()
Recommended Posts