I have the following DataFrame:
df = pd.DataFrame(
{'Column1': ['A', 'B', 'C', 'D'],
'Column2': [['tango', 'bravo', 'alpha'], ['bravo', 'test'], ['romero', 'test'], ['delta']]
})
print(df)
Column1 Column2
0 A [tango, bravo, alpha]
1 B [bravo, test]
2 C [romero, test]
3 D [delta]
I converted the df to a dict like this:
d = {'A': ['tango', 'bravo', 'alpha'],
'B': ['bravo', 'test'],
'C': ['romero', 'test'],
'D': ['delta']}
What I want is to merge all rows (values and keys) that have a common value, which in my case would result in the following dictionary:
d = {"A , B , C": {"tango", "bravo", "alpha" , "bravo", "test", "romero"},
"D": {"delta"}}
This task can be done in the df with pandas or as dictionary, I don't know which one is easier.
"C": {"romero", "test"}?