前処理に使えそうなライブラリ
URL
概要(or Nothing)
サンプルコード(Need)
日本語関連
https://github.com/ikegami-yukino/neologdn
https://github.com/neologd/mecab-ipadic-neologd/wiki/Regexp.ja 準拠で表記ゆれを整える
code:sample.py
import neologdn
neologdn.normalize("ハンカクカナ")
# => 'ハンカクカナ'
neologdn.normalize("全角記号!?@#")
# => '全角記号!?@#'
https://github.com/studio-ousia/mojimoji
convert 半角 to 全角
code:sample.py
>> import mojimoji
>> print mojimoji.zen_to_han(u'アイウabc012')
アイウabc012
https://pypi.org/project/jeraconv/
convert 和暦(str) to 西暦(int)
code:sample.py
from jeraconv import jeraconv
# Create J2W class instance
j2w = jeraconv.J2W()
# ex.1 : General usage
print(j2w.convert('文治6年'))
# result (int) 1190
# ex.2 : Full-width numbers are also available
print(j2w.convert('平成31年'))
# result (int) 2019
# ex.3 : It is also possible to write "1年" as "元年"
print(j2w.convert('令和元年'))
# result (int) 2019
convert 漢数字(str) to 数字(int)
code:sample.py
from kanjize import int2kanji, kanji2int, Number
print(int2kanji(58076099))
# 五千八百七万六千九十九
print(kanji2int("五千八百七万六千九十九"))
# 58076099
https://github.com/delta114514/Japanera
convert 和暦(str) to datetime
janera.strptime の formatが作りこんであってよい
code:sample.py
from japanera import Japanera
janera = Japanera()
janera.strptime('令和元年05月01日', "%-E%-O年%m月%d日")
# datetime.datetime(2019, 5, 1, 0, 0)
janera.strptime('令和01年05月01日', "%-E%-o年%m月%d日")
# datetime.datetime(2019, 5, 1, 0, 0)
import pandas as pd
sample = pd.DataFrame({'date': '令和01年05月01日', '令和02年05月01日'})
# get part of it from list
pd.to_datetime(sample'date'.map(lambda x: janera.strptime(x, "%-E%-o年%m月%d日")).str0)
# 0 2019-05-01
# 1 2020-05-01
# Name: date, dtype: datetime64ns
https://colab.research.google.com/drive/13Ul89U9U2UecB7kXj0Ue8NdIJVW_h2XC