I have a question about make dictionary for keyword count.
This is sample data frame code.
[df code]
df = pd.DataFrame({ "id":[ "100", "200", "300" ], "Text":[ "The best part of Zillow is you can search/view thousands of home within a click of a button without even stepping out of your door.At the comfort of your home you can get all the details such as the floor plan, tax history, neighborhood, mortgage calculator, school ratings etc. and also getting in touch with the contact realtor is just a click away and you are scheduled for the home tour!As a first time home buyer, this website greatly helped me to study the market before making the right choice.", "I love all of the features of the Zillow app, especially the filtering options and the feature that allows you to save customized searches.", "Data is not updated spontaneously. Listings are still shown as active while the Mls shows pending or closed." ], "keyword":[ "[best, word, bus, subway, rain]", "[item, best, school, store, hospital]", "[gym, mall, pool, playground]", ] })
I want to know how many words matching in keyword from Text. And you know, the list length is different.
[fail code]
lst_dic = collections.defaultdict(int) for i in df['id']: for j in (df[df['id'] == i].keyword.values): if df[df['id'] == i].Text.values in j:
As a result, I want to know dictionary key and value. Like this:
[result]
id=100 { 'best':0, 'word':3, 'bus':1, 'subway':0, ... } id=200 { 'item':0, 'best':3, 'school':1, 'store':0, ... }
etc...
Then, I want to extract more than 2 count value of attributes.
Please take a look at this issue.
https://stackoverflow.com/questions/67377933/how-to-count-list-word-in-text-to-make-dictionary-using-python May 04, 2021 at 10:13AM
没有评论:
发表评论