我的数据采用以下格式:
data = [['@datumbox', '#machinelearning'],
['@datumbox', '#textanalysis'],
['@things_internet', '#iot'],
['@things_internet', '#h...'],
['@custmrcom', '#analytics123'],
['@custmrcom', '#strategy...123'],
['@custmrcom', '#1knowledgetweet'],
['@tamaradull', '#@bigbrother']]
Run Code Online (Sandbox Code Playgroud)
我想检查hashtag是否包含任何非字母表.如果是,则删除相应的行.
所需的输出是:
data = [['@datumbox', '#machinelearning'],
['@datumbox', '#textanalysis'],
['@things_internet', '#iot']]
Run Code Online (Sandbox Code Playgroud)
我想我需要使用re.sub(例如,re.compile('[^ a-zA-Z]')).这是我到目前为止:
newdata = []
for item in data:
regex = re.compile('[^a-zA-Z]')
if regex.match(item[1]):
newdata.append([item[0], item[1]])
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?