I created a map where they key is a string and the value is a tuple. I also have a dataframe that looks like this
d = {'comments' : ['This is a bad website', 'The website is slow']}
df = pd.DataFrame(data = d)
The maps value for This is a bad website contains something like this
[("There isn't enough support to our site",
'Staff Not Onsite',
0.7323943661971831),
('I would like to have them on site more frequently',
'Staff Not Onsite',
0.6875)]
What I want to do now is create 6 new columns inside the data frame using the first two tuple entries in the map.
So what I would want is something like this
d = {'comments' : ['This is a bad website', 'The website is slow'],
'comment_match_1' : ['There isn't enough support to our site', ''],
'Negative_category_1' : ['Staff Not Onsite', ''],
'Score_1' : [0.7323, 0],
'comment_match_2' : ['I would like to have them on site more frequently', ''],
'Negative_category_2' : ['Staff Not Onsite', ''],
'Score_2' : [0.6875, 0]}
df = pd.DataFrame(data = d)
Any suggestions on how to achieve this are greatly appreciated.
Here is how I generated the map for reference
d = {}
a = []
for x, y in zip(df['comments'], df['negative_category']):
for z in unlabeled_df['comments']:
a.append((x, y, difflib.SequenceMatcher(None, x, z).ratio()))
d[z] = a
Thus when I execute this line of code
d['This is a bad website']
I get
[("There isn't enough support to our site",
'Staff Not Onsite',
0.7323943661971831),
('I would like to have them on site more frequently',
'Staff Not Onsite',
0.6875), ...]
key:valuepair?...indicates that there is a lot more tuples. I am just interested in the first two.