Pykakasi -Google Colaboratory-出力エラーの解消について
仕事で漢字を読む作業を自動化したくpythonに取り組んでいる過程で、以下のような問題に直面しております。どなたか助言頂けますと幸いです。
Google ColaboratoryにてPykakasi(https://github.com/miurahr/pykakasi)を活用し漢字を自動判別しようとしておりましたが、出力に問題が起きておりますのでここにご相談させて頂いております。
実行環境は以下です。
デバイス:Windows10
開発環境:Google Colaboratory
スプレッドシートから漢字を読み込み、ローマ字に直すというコードを作成しておりますが、出力結果が通常のエラーと異なりファイルのパス(?)のようのものが出てきている状態です。
発生している問題・エラー
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:9: DeprecationWarning: Call to deprecated method setMode. (Old API will be removed in v3.0.) -- Deprecated since version 2.1.
if __name__ == '__main__':
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:10: DeprecationWarning: Call to deprecated method getConverter. (Old API will be removed in v3.0.) -- Deprecated since version 2.1.
# Remove the CWD from sys.path while we load stuff.
/usr/local/lib/python3.7/dist-packages/ipykernel_launcher.py:11: DeprecationWarning: Call to deprecated method do. (Old API will be removed in v3.0.) -- Deprecated since version 2.1.
# This is added back by InteractiveShellApp.init_path()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-96-6d3564a7d988> in <module>()
9 kks.setMode('J', 'a')
10 conv = kks.getConverter()
---> 11 conv.do(row1)
3 frames
/usr/local/lib/python3.7/dist-packages/deprecated/classic.py in wrapper_function(wrapped_, instance_, args_, kwargs_)
283 else:
284 warnings.warn(msg, category=category, stacklevel=_routine_stacklevel)
--> 285 return wrapped_(*args_, **kwargs_)
286
287 return wrapper_function(wrapped)
/usr/local/lib/python3.7/dist-packages/pykakasi/legacy.py in do(self, text)
134 if mode in ("J", "E"):
135 w = min(i + _MAXLEN, len(text))
--> 136 (t, l1) = self._conv[mode].convert(text[i:w])
137
138 if l1 > 0:
/usr/local/lib/python3.7/dist-packages/pykakasi/legacy.py in convert_nonh(self, text)
302 return "", 0
303
--> 304 (t, l1) = self.convert_h(text)
305 if l1 <= 0: # pragma: no cover
306 return "", 0
/usr/local/lib/python3.7/dist-packages/pykakasi/legacy.py in convert_h(self, itext)
296
297 def convert_h(self, itext) -> Tuple[str, int]:
--> 298 return self._jconv.convert(itext)
299
300 def convert_nonh(self, text):
TypeError: unhashable type: 'list'
該当するソースコード
pip install git+https://github.com/miurahr/pykakasi
from pykakasi import kakasi
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials
print(gspread.__version__)
!pip install --upgrade gspread
#実際の実行時には上記gspreadの認証と以下はセルを分けています。
gc = gspread.authorize(GoogleCredentials.get_application_default())
worksheet = gc.open_by_url('https://docs.google.com/spreadsheets/d/1pGNCrstOBL7CSb4eIcz4zNmFbDGYTAbKIFeH3VNSRFw/edit#gid=0').sheet1
row1 = worksheet.col_values(1)
for row in row1:
kks = kakasi()
kks.setMode('J', 'a')
conv = kks.getConverter()
conv.do(row1)
自分で試したこと
csvで実行した際は問題なくできていたのですが、スプレッドシートだとうまくいっていません。
Colaboratoryでは初期設定のpythonが3.7と聞いたので3.8にアップデートし、スプレッドシートもアップデートしたのですがどうやらコードに問題があるようです。
素人質問で大変恐縮なのですが、どなたかご教示頂けますと幸いです。