What is the best way to merge a df
like this:
+------------+----------+
| domain | username |
+------------+----------+
| @gmail.com | gagaga |
+------------+----------+
| @mail.com | bobo |
+------------+----------+
with a dict like this:
domain_to_app = {
'@gmail.com': ['gmail', 'youtube', 'gdrive'],
'@mail.com': ['email', 'dropbox']
}
to get this:
+------------+----------+-----------+
| domain | username | app |
+------------+----------+-----------+
| @gmail.com | gagaga | gmail |
+------------+----------+-----------+
| @gmail.com | gagaga | youtube |
+------------+----------+-----------+
| @gmail.com | gagaga | gdrive |
+------------+----------+-----------+
| @mail.com | bobo | email |
+------------+----------+-----------+
| @mail.com | bobo | dropbox |
+------------+----------+-----------+
Is it recommended to convert the dict
into a df
with repeating rows and use merge
, or should i use map
then unstack the app column?