我怎样才能把弦从弓矢上取回来?

2024-04-20 07:17:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经为名为tech_raw_data['Product lower']的pandas dataframae列生成了BoW。你知道吗

count_vect = CountVectorizer()
smer_counts = count_vect.fit_transform(tech_raw_data['Product lower'].values.astype('U'))
smer_vocab = count_vect.get_feature_names()

为了测试字符串与这个BoW向量的相似性,我在dataframe的列中只为一个条目toys['ITEM NAME']创建了BoW。你知道吗

 toys = pd.read_csv('toy_data.csv', engine='python')
 print('-'*80)
 print(toys['ITEM NAME'].iloc[0])
 print('-'*80)
 inp = [toys['ITEM NAME'].iloc[0]]

 cust_counts = count_vect.transform(inp)
 cust_vocab = count_vect.get_feature_names()

检查相似性:

def similar(a, b):
    return SequenceMatcher(None, a, b).ratio()

for x in cust_counts[0].toarray():
    for y in smer_counts.toarray():
        ratio = similar(x, y)
        #print(ratio)
        if ratio>=0.85:
            should print the string corresponding to BoW y

现在,每当匹配比超过0.85时,我需要打印与tech_raw_data['Product lower']数据帧中的smer_counts对应的字符串。你知道吗


Tags: namedatarawcountproductitemlowertech
1条回答
网友
1楼 · 发布于 2024-04-20 07:17:44
for x in cust_counts[0].toarray():
    for i, y in enumerate(smer_counts.toarray()):
        ratio = similar(x, y)
        #print(ratio)
        if ratio>=0.85:
            print (tech_raw_data.loc[i, 'Product lower'])

枚举smer_counts.toarray()返回的numpy数组,并在ratio>=0.85返回时使用索引来获取tech_raw_data数据帧中的相应文本。你知道吗

这是有效的,因为len(smer_counts.toarray()) == len(tech_raw_data)以及数据帧中记录的顺序都被保留。你知道吗

相关问题 更多 >