首页 > 解决方案 > 'function' 对象在 Python 中不可下标

问题描述

我尝试使用此代码:

def tw_list(text):
  tw_list['text'] = tw_list['text'].str.lower()


print('Case Folding Result : \n')
print(tw_list['text'].head(5))
print('\n\n\n')

但是当我运行它时,我得到了错误:

Case Folding Result : 

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-c3ee7c744c13> in <module>
      6 
      7 print('Case Folding Result : \n')
----> 8 print(tw_list['texts'].head(5))
      9 print('\n\n\n')

TypeError: 'function' object is not subscriptable

我不知道为什么,有人可以帮助我吗?

标签: pythonjupyter-notebook

解决方案


tw_list 是您的函数的名称。 您正在尝试以 dict 的形式访问该函数。因此它会引发错误


推荐阅读