我目前正在试验python数据库,并请求它们提供信息。我正在尝试检查数据集(csv文件):
Keyword, Word_num
hello,3
yup,4
yup,5
与输入的字符串共享单词。这是我目前掌握的情况。你知道吗
import csv
import pandas as pd
#creates data set
df = pd.read_csv('Keywords.csv', index_col = 'word_num')
print(df)
print('///////////////////////////////////////////////////////////////////')
#new string for used to check for similatiry
input = 'yup world earthlings'
input = input.split()
#checking for cells andy words in common with 'x'
df = df[df['Keyword'].str.contains('|'.join(input))]
print(df)
到目前为止,这只输出熊猫数据集形式的数据:
Keyword
1 yup
我想做的是让我的输出成为存储的字符串('yup')。你知道吗
试试看
首先,请以可复制的方式分享您的问题,以便其他人可以创建您的数据,例如:
其次,不要用保留的特殊关键字命名任何对象。
input
是Python中的一个特殊术语,用于处理用户输入。因此,请将您的对象命名为my_input
或类似的普通名称。你知道吗现在您要做的是获取这个字符串的每个元素,并检查它们是否存在于您的
df
的Keyword
列中。好吧,做一个循环,就是这样:让我知道这是否有帮助或如果你需要进一步的协助。你知道吗
相关问题 更多 >
编程相关推荐