pandas Hiragana → Katakana conversion

When editing CSV using pandas, I want to convert the value of the whole specific column. There is a process to change from half-width characters to full-width characters by searching on the net, but I could not find a process to convert from hiragana to katakana. I made a method of changeKana and implemented it to call changeKana via maketrans.

df = pandas.read_csv(file, encoding='cp932', engine='python', dtype=object)

Half-width → full-width df [column name] = df [column name] .str.translate (str.maketrans ({chr (0x0021 + i): chr (0xFF01 + i) for i in range (94)})) Hiragana → Katakana df [column name] = df [column name] .str.translate (str.maketrans ({chr (x): changeKana (chr (x)) for x in range (12353, 12436)}))

#Pattern 1: Half-width → Full-width #Pattern 2: Hiragana → Katakana def changeKana(in_Word):

Actually, there is no need to change half-width → full-width

    changeWord = jaconv.h2z(in_Word)
    changeWord = jaconv.hira2kata(changeWord)

    return changeWord

Recommended Posts

pandas Hiragana → Katakana conversion
Pandas
Reverse Hiragana and Katakana in Python2.7