0

I created a dataframe

    team3   team4   Dummy
0   F   YG  10
1   g   Gh  10
2   h   Ya  10
3   i   nG  10
4   k   Yb  10
5   l   Yf  10
6   m   jk  10

and i'm trying to get expected output as below

    team3          team4                  Dummy
0   F|g|h|i|k|l|m   YG|gh|ya|ng|yb|yf|jk    10


df10 = df9.groupby('Dummy')['team3','team4'].apply('|'.join).reset_index()

getting error :

FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead. df10 = df9.groupby('Dummy')['team3','team4'].apply('|'.join).reset_index()

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252

1 Answers1

0

Add nested list for select multiple columns and instead GroupBy.apply use GroupBy.agg for processing each column separately:

#joined columns names
print (df9.groupby('Dummy')[['team3','team4']].apply('|'.join).reset_index())
   Dummy            0
0     10  team3|team4

df10 = df9.groupby('Dummy')[['team3','team4']].agg('|'.join).reset_index()
print (df10)
   Dummy          team3                 team4
0     10  F|g|h|i|k|l|m  YG|Gh|Ya|nG|Yb|Yf|jk

If order is important:

df10 = df10[['team3','team4','Dummy']]
print (df10)
           team3                 team4  Dummy
0  F|g|h|i|k|l|m  YG|Gh|Ya|nG|Yb|Yf|jk     10
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252