I have the following pandas DataFrame:
import pandas as pd
df = pd.DataFrame({
'name': ['John', 'Jack', 'John', 'Tim', 'John'],
'city': ['New York', 'London', 'Paris', 'Berlin', 'New York'],
'nickname': ['aaa', 'bbb', 'ccc', 'ddd', 'eee']
})
I'm trying to group based on the condition that if values in columns name and city are same we add the values in column nickname. Result for the above DataFrame should look like this:
I'm using the below groupby function but the values under nickname column aren't getting concatenated as they are strings.
df1 = df.groupby(['name','city'])['nickname'].apply(' '.join())
but the above code does not concatenate cell values in column nickname
Can anyone help?
