Imagine I have a dataframe that contains a candidate and his skills in varrious languages both written and spoken:
df = pd.DataFrame({'candidate': ['a', 'a', 'a', 'b', 'b', 'c', 'c', 'd', 'd', 'd'],
'type': ['spoken', 'written', 'spoken', 'written', 'spoken', 'written', 'spoken', 'written', 'written', 'written'],
'language': ['English', 'German', 'French', 'English', 'English', 'English', 'French', 'English', 'German', 'French'],
'skill': [5, 4, 4, 6, 8, 1, 3, 5, 2, 2]})
result:
candidate type language skill
a spoken English 5
a written German 4
a spoken French 4
b written English 6
b spoken English 8
c written English 1
c spoken French 3
d written English 5
d written German 2
d written French 2
and another df with languages:
languages = pd.DataFrame({'language': ['English', 'English', 'French', 'French', 'German', 'German'],
'type': ['spoken', 'written', 'spoken', 'written', 'spoken', 'written']})
result:
language type
0 English spoken
1 English written
2 French spoken
3 French written
4 German spoken
5 German written
What I need to get is a dataframe that combines df and all possible combinations of its merge with languages, so:
candidate type language skill
a spoken English 5
a written English NA
a spoken German NA
a written German 4
a spoken French 4
a written French NA
b spoken English 8
b written English 6
b spoken French NA
b written French NA
...
d spoken English NA
d written English 5
d spoken French NA
d written French 2
d spoken German NA
d written German 2
and so on. I was trying to add a 'valid' column filled with 'valid' value and use all kind of merges on these dataframes but it always returns only df. Is there any swift way to cope with it in pandas?