Python 在列中搜索字符串的实例。TypeError:列表索引必须是整数,而不是str
我正在清理一些twitter API数据,我正在寻找一个字符串的实例。在本例中,使用“大数据”作为示例。但我的错误是需要整数而不是字符串 这很奇怪,因为我看到的列“Text”是字符串而不是整数。我需要它们是字符串,这样我就可以搜索我要查找的文本的实例Python 在列中搜索字符串的实例。TypeError:列表索引必须是整数,而不是str,python,string,pandas,Python,String,Pandas,我正在清理一些twitter API数据,我正在寻找一个字符串的实例。在本例中,使用“大数据”作为示例。但我的错误是需要整数而不是字符串 这很奇怪,因为我看到的列“Text”是字符串而不是整数。我需要它们是字符串,这样我就可以搜索我要查找的文本的实例 DataSet.head() tweetID Text coordinates followerCount friendsCount
DataSet.head()
tweetID Text coordinates followerCount friendsCount Location Name Lang screenName createdAt timeZone
0 1514313588 #Analytics #Jobs: #Data Scientist @ https://t.... None 760 2029 None claap en goCLAAP Thu Jun 13 20:06:03 +0000 2013 None
1 3161843418 RT @asokan_telecom: How 2 Manage Sucessful #Bi... None 564 0 None RA Fisher en dataproblems Sat Apr 18 04:15:08 +0000 2015 None
2 95143217 Sensors & big-data analytics measure &... None 422 306 Singapore Stacey Albert en StaceyGAlbert Mon Dec 07 05:32:49 +0000 2009 Singapore
3 3319297545 RT @BurtchWorks: Looking for a Data Scientist ... None 165 161 Evanston, IL emazeMe Evanston en eMazingEvanston Thu Jun 11 17:59:22 +0000 2015 None
4 26489112 Upcoming webinar: Interactive Business Intelli... None 1276 1677 North America/EMEA Perficient Life Sci en Perficient_LS Wed Mar 25 12:50:21 +0000 2009 Central Time (US & Canada)
我尝试使用以下命令从“文本”列中提取字符串实例:
tweets['big data'] = DataSet['Text'].str.contains(r'big data', na=False)
但我得到了这个错误:
TypeError: list indices must be integers, not str
但这没有意义,我需要将此列作为字符串来查找字符串的实例
我在这里遗漏了什么?多亏了安东波波夫才解决了这个问题。我没有正确命名数据帧
DataSet['big data'] = DataSet['Text'].str.contains(r'big data', na=False)
你的
推文是什么类型的
?谢谢@antonprotopov我解决了它!