使用 pandas 进行主题分析

问题描述 投票:0回答:0

所以我正在使用 gensim for LDA 对 csv 文件进行主题建模;我面临的问题是在熊猫中,这是代码 -

d_s['text_clean'] = d_s['text'].apply(clean)

这是错误

PS C:\Users\SanchitBhansali\Desktop\Topic extraction> & C:/Users/SanchitBhansali/AppData/Local/Microsoft/WindowsApps/python3.10.exe "c:/Users/SanchitBhansali/Desktop/Topic extraction/topic analysis.py"
Traceback (most recent call last):
  File "C:\Users\SanchitBhansali\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\core\indexes\base.py", line 3800, in get_loc
    return self._engine.get_loc(casted_key)
  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\hashtable_class_helper.pxi", line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas\_libs\hashtable_class_helper.pxi", line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'text'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "c:\Users\SanchitBhansali\Desktop\Topic extraction\topic analysis.py", line 27, in <module>
    d_s['text_clean'] = d_s['text'].apply(clean)
  File "C:\Users\SanchitBhansali\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\core\frame.py", line 3805, in __getitem__
    indexer = self.columns.get_loc(key)
  File "C:\Users\SanchitBhansali\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\pandas\core\indexes\base.py", line 3802, in get_loc
    raise KeyError(key) from err
KeyError: 'text'
PS C:\Users\SanchitBhansali\Desktop\Topic extraction> 

我不太明白这个错误,我是大熊猫的新手。我在做主题建模

python pandas machine-learning gensim topic-modeling
© www.soinside.com 2019 - 2024. All rights reserved.