поэтому я попытался создать облако слов для каждой строки моего фрейма данных, однако я получаю сообщение «Ошибка ключа», хотя вводимый мной ключ находится во фрейме данных. Ниже я получаю сообщение об ошибке.
TypeError Traceback (most recent call last)
~\Anaconda5\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4380 try:
-> 4381 return libindex.get_value_box(s, key)
4382 except IndexError:
pandas/_libs/index.pyx in pandas._libs.index.get_value_box()
pandas/_libs/index.pyx in pandas._libs.index.get_value_at()
pandas/_libs/util.pxd in pandas._libs.util.get_value_at()
pandas/_libs/util.pxd in pandas._libs.util.validate_indexer()
TypeError: 'str' object cannot be interpreted as an integer
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-199-ad0259072d85> in <module>
15 # Create subplots for each comedian
16 for index, i in enumerate(data_clean1.columns):
---> 17 wc.generate(data_clean1.Tweet_Content[i])
18
19 plt.subplot(3, 4, index+1)
~\Anaconda5\lib\site-packages\pandas\core\series.py in __getitem__(self, key)
866 key = com.apply_if_callable(key, self)
867 try:
--> 868 result = self.index.get_value(self, key)
869
870 if not is_scalar(result):
~\Anaconda5\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4387 raise InvalidIndexError(key)
4388 else:
-> 4389 raise e1
4390 except Exception: # pragma: no cover
4391 raise e1
~\Anaconda5\lib\site-packages\pandas\core\indexes\base.py in get_value(self, series, key)
4373 try:
4374 return self._engine.get_value(s, k,
-> 4375 tz=getattr(series.dtype, 'tz', None))
4376 except KeyError as e1:
4377 if len(self) > 0 and (self.holds_integer() or self.is_boolean()):
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Tweet_Content'
код
wc = WordCloud(stopwords=stop_words, background_color="white", colormap="Dark2",
max_font_size=150, random_state=42)
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [16, 6]
full_names = ['AdibJalal', 'Cedders31', 'CoconutsSG', 'EricssenWen', 'Ivkov', 'KambingTribune', 'Michael65413248', 'Min_tos',
'MothershipSG', 'Naim_broke', 'Narathedeeer', 'PeacemindWater', 'SCMPAsia', 'STcom', 'TODAYonline', 'ThinkNotInform',
'TrendsSingapore', 'bignoodlesyeo', 'cheanliang', 'cheriangeorge', 'cloudywind', 'colinctc', 'coolinsights', 'gregg_chen',
'haresh96', 'harishpillay', 'hidzdotfm', 'insidestorymag', 'intrepidynamite', 'jamuslim',
'jbhavan', 'rudeshock', 'sayskelly', 'sgjul2020', 'shyhjih', 'sudhirtv', 'sumanpriya', 'tocsg']
# Create subplots for each author
for index, i in enumerate(data_clean1.columns):
wc.generate(data_clean1.Tweet_Content[i])
plt.subplot(3, 4, index+1)
plt.imshow(wc, interpolation="bilinear")
plt.axis("off")
plt.title(full_names[index])
plt.show()