Character code conversion of CSV file using Loop (Shift JIS to UTF8)

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

Character code conversion of CSV file using Loop (Shift JIS to UTF8)
Handling of character code of file in IronPython
[Python] Get the character code of the file
[Python] [chardet] Automatic detection of character code of file
Convert the character code of the file with Python3
2.x, 3.x character code of python
Output search results of posts to a file using Mattermost API
How to create a CSV dummy file containing Japanese using Faker