前提・実現したいこと
現在、googleフォームのデータを使いやすい形に変換するプログラムを書いているのですが、以下のようなエラーが出ます。
調べている感じ日本語の文字コードが原因だと思うのですが、辞書自体はUTF8になっているので対処法が分かりません。
お手数ですが、どなたかわかる人ご対応お願いいたします。
環境はlinuxです。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "form_answer.py", line 70, in <module> print(df) UnicodeEncodeError: 'utf-8' codec can't encode characters in position 36-37: surrogates not allowed
該当のソースコード
python
1#処理しやすい形式に変換 2def data_arrange(database): 3 answer=[] 4 m = MeCab.Tagger("mecabrc") 5 for item in range(1,len(database[0]),3): 6 node=m.parseToNode(database[0][item].strip() 7 while True: 8 fields=node.feature.split(",") 9 if fields[0]=="記号": 10 node=node.next 11 for hikensya in range(1,len(database)): 12 text=[] 13 text.append("['"+node.surface+"']") 14 for kind in range(3): 15 number=database[hikensya][item+kind] 16 text.append(number[0]) 17 answer.append(text) 18 break 19 node=node.next 20 answer_pd=pd.DataFrame(answer) 21 return answer_pd 22 23 24 25if __name__ == '__main__': 26 # フォルダ中のパスを取得 27 target_dir=sys.argv[1] 28 DATA_PATH = "./"+ target_dir +"/" 29 All_Files = glob.glob('{}*.csv'.format(DATA_PATH)) 30# フォルダ中の全csvをマージ 31 list = [] 32 for file in All_Files: 33 csvfile=open(file,"r",encoding="utf-8") 34 pre_df=csv.reader(csvfile) 35 database=[row for row in pre_df] 36 answer=data_arrange(database) 37 list.append(answer) 38 df = pd.concat(list,sort=False) 39 print(df)
試したこと
mecabのバージョンを確認しました。
filename: /usr/lib/arm-linux-gnueabihf/mecab/dic/mecab-ipadic-neologd/sys.dic
version: 102
charset: UTF8
type: 0
size: 4668394
left size: 1316
right size: 1316
回答2件
あなたの回答
tips
プレビュー