I have a Pandas DF which holds names of music albums and various information. There are multiple records for the same music artists. I would like to produce a dictionary from this where the key = the artist name and the value = a list of the albums for the artist:
The example pandas df looks like this:
artist album
0 A-ha Headlines And Deadlines: The Hits Of A-Ha
1 Abba Greatest Hits Vol. 2
2 abc The Lexicon Of Love
3 AC/DC Back In Black
4 AC/DC Highway to Hell
5 All About Eve All About Eve
6 Jon Anderson Olias of Sunhillow
7 Jon Anderson Song of Seven
The output I want is:
output = {
'A-ha': ['Headlines And Deadlines: The Hits Of A-Ha'],
'Abba': ['Greatest Hits Vol. 2'],
'abc': ['The Lexicon Of Love'],
'AC/DC': [['Back In Black'],['Highway to Hell']],
'All About Eve': ['All About Eve'],
'Jon Anderson': [['Olias of Sunhillow'],['Song of Seven']]
}
I have tries looping through the dataframe and also df.to.dict options but I haven't been able to produce my required output.
I get this warning from pandas: UserWarning: DataFrame columns are not unique, some columns will be omitted.
Thanks