import re
import pandas as pd
import sqlite3
connection = sqlite3.connect('C:\Users\wh112\Desktop\BRAIN.sqlite')
df1 = pd.read_sql('select * from PRONOUN',connection)
df2 = pd.read_sql('select * from VERB',connection)
df3 = pd.read_sql('select * from QUESTIONS',connection)
df = pd.concat([df1,df2,df3])
def word_list(text):
return list(filter(None, re.split('\W+', text)))
session = raw_input("Test on me!")
feedback = session
print(word_list(feedback))
dff = pd.DataFrame({'Sentence':[feedback]})
dff['1'] = dff['Sentence'].astype(str).str.split().str[0]
dff['2'] = dff['Sentence'].astype(str).str.split().str[1]
dff['3'] = dff['Sentence'].astype(str).str.split().str[2]
for pts1 in dff['1']:
pts1 = df.columns[df.isin([pts1]).any()]
for pts2 in dff['2']:
pts2 = df.columns[df.isin([pts2]).any()]
for pts3 in dff['3']:
pts3 = df.columns[df.isin([pts3]).any()]
现在主题开启:
pts1 = df.columns[df.isin([pts1]).any()]
当我使用它从数据库字符串中查找任何匹配项时;多个匹配项一起显示在输出上。像这样:
Index([u'auxiliary_verbfirst_person_singular_pronounnon_wh_type'])
但我希望他们像这样一个一个地成为一个
Index([u'auxiliary_verb, first_person_singular_pronoun,non_wh_type'])
有没有办法做到这一点,请你帮我吗?