「historyproto」が二重のリストにならないように下記を変更
historyproto = [text.split('\n\n\n')]
↓ 変更
historyproto = text.split('\n\n\n')
最後のforループ内を下記のように変更
(インデントは正しく入れてください)
proton = [''.join(x).split()[0] for line in m.parse(text).splitlines()]
for y in proton:
history.append(y)
↓ 変更
proton = x.split()
if len(proton) != 0:
history.append(proton)
そうすれば、「history」は二次元のリストになりますけど、意図に合ってますでしょうか?
【追記】
コードの最後に下記を追加して実行したら、「history」の各行の要素数と要素が分かります
(forループ内のインデントは正しく入れてください)
print("history")
print(len(history))
print(history)
print("history2")
for i in range(len(history)):
print(len(history[i]))
print(history[i])
> Ochasenで名刺だけを取り出したい
最後のforループ内を下記のように変更
(インデントは正しく入れてください)
proton = [''.join(x).split()[0] for line in m.parse(text).splitlines()]
for y in proton:
history.append(y)
↓ 変更
proton = [line.split()[0] for line in m.parse(x).splitlines() if "名詞" in line.split()[-1]]
if len(proton) != 0:
history.append(proton)
参考
https://note.com/junmaeda/n/n39b8b286da13
もう一つの変更も要ります
(「historyproto」が二重のリストにならないようにするやつ)
回答で実行した結果です.
Traceback (most recent call last):
File "/Users/**/**/**/***.py", line 36, in <module>
proton = [line.split()[0] for line in m.parse(x).splitlines() if "名詞" in line.split()[-1]]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/MeCab.py", line 293, in parse
return _MeCab.Tagger_parse(self, *args)
TypeError: in method 'Tagger_parse', argument 2 of type 'char const *'
Additional information:
Wrong number or type of arguments for overloaded function 'Tagger_parse'.
Possible C/C++ prototypes are:
MeCab::Tagger::parse(MeCab::Model const &,MeCab::Lattice *)
MeCab::Tagger::parse(MeCab::Lattice *) const
MeCab::Tagger::parse(char const *)
一つ前のコメントに書いたように、google colabではエラーは出ませんので、下記エラーは質問者さんのパソコン環境固有の問題だと思います
> 回答で実行した結果です.
Traceback (most recent call last):
File "/Users/**/**/**/***.py", line 36, in <module>
proton = [line.split()[0] for line in m.parse(x).splitlines() if "名詞" in line.split()[-1]]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/MeCab.py", line 293, in parse
return _MeCab.Tagger_parse(self, *args)
TypeError: in method 'Tagger_parse', argument 2 of type 'char const *'
Additional information:
Wrong number or type of arguments for overloaded function 'Tagger_parse'.
Possible C/C++ prototypes are:
MeCab::Tagger::parse(MeCab::Model const &,MeCab::Lattice *)
MeCab::Tagger::parse(MeCab::Lattice *) const
MeCab::Tagger::parse(char const *)