Как исправить KeyError: 'текст' в кадре данных панд? - PullRequest
0 голосов
/ 30 сентября 2018

У меня очень большой набор твитов, которые я предварительно обработал.В этом очищенном CSV-файле есть два столбца: имена и текст в указанном порядке.Я пытался тренироваться на этих данных, но каждый раз, когда я пытаюсь использовать данные, я получаю ключевую ошибку.

Traceback (most recent call last):
  File "sentiment_classifier.py", line 17, in <module>
    tweet_text = twitter_data['text']
  File "C:\Users\Aeryes\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2688, in __getitem__
    return self._getitem_column(key)
  File "C:\Users\Aeryes\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 2695, in _getitem_column
    return self._get_item_cache(key)
  File "C:\Users\Aeryes\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 2489, in _get_item_cache
    values = self._data.get(item)
  File "C:\Users\Aeryes\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\internals.py", line 4115, in get
    loc = self.items.get_loc(item)
  File "C:\Users\Aeryes\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexes\base.py", line 3080, in get_loc
    return self._engine.get_loc(self._maybe_cast_indexer(key))
  File "pandas\_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc
  File "pandas\_libs\index.pyx", line 164, in pandas._libs.index.IndexEngine.get_loc
KeyError: 'text'

Я пробовал следующее, чтобы заставить его работать должным образом:

  • Я заметил, что в текстовом столбце моего набора данных были пустые области для примерно 3200 из 1,6 миллиона записей.Я попытался использовать twitter_data.dropna(inplace=True), чтобы удалить эти пустые поля перед подачей данных в мой LSTM.

  • Я также попытался tweet_text = twitter_data['text'] = [tweet.get('text','') for tweet in twitter_data if tweet.isaplha()] отфильтровать любые типы int в текстовом поле после того, как яполучил эту ошибку:

sys: 1: DtypeWarning: Столбцы (0) имеют смешанные типы.Укажите опцию dtype при импорте или установите low_memory = False.Traceback (последний вызов был последним): файл "sentiment_classifier.py", строка 17, в tweet_text = twitter_data ['text'] = [tweet.get ('text', '') для твита в файле twitter_data] файл "sentiment_classifier.py", строка 17, в tweet_text = twitter_data ['text'] = [tweet.get ('text', '') для твита в twitter_data] AttributeError: у объекта int нет атрибута 'get'

Я понятия не имею, как двигаться вперед и решить эту проблему.Пожалуйста, помогите мне.

Я добавил ошибку, которая появляется при печати twitter_data.keys ()

sys:1: DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.
Int64Index([0, 1], dtype='int64')

Я получаю этот вывод при печати twitter_data:

sys:1: DtypeWarning: Columns (0) have mixed types. Specify dtype option on import or set low_memory=False.
               0                                                  1
0          index                                               text
1              0  awww that bummer you shoulda got david carr of...
2              1  is upset that he can not update his facebook b...
3              2  dived many times for the ball managed to save ...
4              3     my whole body feels itchy and like its on fire
5              4  no it not behaving at all mad why am here beca...
6              5                                 not the whole crew
7              6                                           need hug
8              7  hey long time no see yes rains bit only bit lo...
9              8                          nope they did not have it
10             9                                       que me muera
11            10              spring break in plain city it snowing
12            11                            just re pierced my ears
13            12  could not bear to watch it and thought the ua ...
14            13  it it counts idk why did either you never talk...
15            14  would ve been the first but did not have gun n...
16            15  wish got to watch it with you miss you and how...
17            16  hollis death scene will hurt me severely to wa...
18            17                                about to file taxes
19            18  ahh ive always wanted to see rent love the sou...
20            19  oh dear were you drinking out of the forgotten...
21            20   was out most of the day so did not get much done
22            21  one of my friend called me and asked to meet w...
23            22                         baked you cake but ated it
24            23                this week is not going as had hoped
25            24                            blagh class at tomorrow
26            25          hate when have to call and wake people up
27            26  just going to cry myself to sleep after watchi...
28            27                              im sad now miss lilly
29            28  ooooh lol that leslie and ok will not do it ag...
...          ...                                                ...
1596012  1599969  you re the undisputed authority on the topic g...
1596013  1599970   thanks thanks that was just what was looking for
1596014  1599971  thanks martin not the most imaginative interfa...
1596015  1599972                            congrats mike way to go
1596016  1599973                    omg office space wanna steal it
1596017  1599974  ahaha nooo you were just away from everyone el...
1596018  1599975  hey baack and thanks so much for all those kin...
1596019  1599976     yeah my conscience would be clear in that case
1596020  1599977               thats my girl dishing out the advice
1596021  1599978                                        second that
1596022  1599979                                      in the garden
1596023  1599980         jo jen by nemuselo zrovna holce ael co nic
1596024  1599981                     another commenting contest yay
1596025  1599982  figured out how to see my tweets and facebook ...
1596026  1599983  theri tomorrow drinking coffee talking about o...
1596027  1599984  you heard it here first we re having girl hope...
1596028  1599985  if ur the lead singer in band beware falling p...
1596029  1599986                            too much ads on my blog
1596030  1599987  neveer think that you both will get on well wi...
1596031  1599988  ha good job that right we gotta throw that big...
1596032  1599989                              im glad ur doing well
1596033  1599990                                wooooo xbox is back
1596034  1599991  mmmm that sounds absolutely perfect but my sch...
1596035  1599992                   recovering from the long weekend
1596036  1599994  yeah that does work better than just waiting f...
1596037  1599995  just woke up having no school is the best feel...
1596038  1599996   thewdb com very cool to hear old walt interviews
1596039  1599997  are you ready for your mojo makeover ask me fo...
1596040  1599998  happy th birthday to my boo of alll time tupac...
1596041  1599999                               happy charitytuesday

[1596042 rows x 2 columns]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...