Q:

reshape python concatenate text irregular dataframe

I'm very new to Python and pandas in particular. I've got an irregular reshape problem where I want to concatenate all strings from one column of the dataframe where an id variable matches from the other column. It is an irregular reshape problem because the number of concatenations that need to be done may differ depending on the id.
So for example: 
import pandas as pd 
import numpy as np 
df = pd.read_csv('sample.txt') 
print df 

   id text
0   1  ABC
1   1  BCD
2   2  CDE
3   2  DEF
4   2  EFG
5   3  FGH

I would like to use id to reshape, and concatenate all text for the cases where id matches, resulting in something like this: 
print(df_new):  
   id         text
0   1      ABC BCD
1   2  CDE DEF EFG
2   3          FGH

A:

Use groupby with aggregating join:
print (df.groupby('id')['text'].apply(' '.join).reset_index())
   id         text
0   1      ABC BCD
1   2  CDE DEF EFG
2   3          FGH

