I have two tables, or rather, Pandas Dataframes, calls and tags that look like:
calls
id | tags
--------
01 | [tag1]
02 | [tag1, tag2]
03 | []
tags
id | tag_name
-------------
01 | tag1
02 | tag2
And I want a resulting DF like:
matching table
id | calls_id | tag_id
----------------------
01 | 01 | 01
02 | 02 | 01
02 | 02 | 02
03 | |
So essentially I'm trying to match each call with its respective tags in a seperate DF
My best approach so far was:
def match_tags(x):
insert_df = pd.DataFrame(columns=['call_id', 'tag_id'])
for y in x['tags']:
insert_df = insert_df.append({'call_id':x.id, 'tag_id': tags_df['id'].loc[y]}, ignore_index=True)
insert_df.head()
return insert_df
calls_df.apply(lambda x: pd.concat([tag_matching_df, match_tags(x)]), axis=1)
I'm not certain that a lambda function is the right solution here.