Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas group by concat

In [124]:

df.groupby(['name','month'])['text'].apply(lambda x: ','.join(x)).reset_index()

Out[124]:
    name  month         text
0  name1     11       hej,du
1  name1     12        aj,oj
2  name2     11     fin,katt
3  name2     12  mycket,lite
Comment

Concatenate strings using Pandas groupby

In[38]:
df.groupby(['name','month'])['text'].apply(','.join).reset_index()

Out[38]: 
    name  month         text
0  name1     11           du
1  name1     12        aj,oj
2  name2     11     fin,katt
3  name2     12  mycket,lite
Comment

PREVIOUS NEXT
Code Example
Python :: ses mail name 
Python :: scikit learn split data set 
Python :: tkinter entry read only 
Python :: spacex 
Python :: sorting pandas dataframe like excel 
Python :: how to import random module in python 
Python :: how to check python version in cmd 
Python :: get first element list of tuples python 
Python :: run sql query on pandas dataframe 
Python :: how to subtract dates in python 
Python :: django models distinct 
Python :: bisect_left in python 
Python :: roll longitude about zero 
Python :: how to load wav file python 
Python :: tkinter app icon 
Python :: python check folder exist 
Python :: python finite difference approximation backward difference 
Python :: python remove all except numbers 
Python :: first row as column df 
Python :: TypeError: dict is not a sequence 
Python :: dropping columns in pandas 
Python :: pandas conditional replace values in a series 
Python :: pandas change column name from a dictionary 
Python :: opencv skip video frames 
Python :: execute python in notepad++ 
Python :: find allurl in text python 
Python :: drop row based on NaN value of a column 
Python :: TabError: inconsistent use of tabs and spaces in indentation 
Python :: parse first characters from string python 
Python :: how to hide command console python 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =