I'm trying to group a DataFrame which consists of a DocID and a string using this SO as guide but instead of a dataframe with 1 row per DocID and all the string values separated by a space, I end up with a column containing the column values.
Can someone point out my error?
Sample Data
StringDF.head()
DocID LessStopWords
0 dd9ae7c8-7e98-4539-ab81-24c4780a6756 judgment of the court chamber
1 dd9ae7c8-7e98-4539-ab81-24c4780a6756 the request proceedings
2 dd9ae7c8-7e98-4539-ab81-24c4780a6756 legal context law
3 dd9ae7c8-7e98-4539-ab81-24c4780a6756 article 1 directive
4 dd9ae7c8-7e98-4539-ab81-24c4780a6756 the status taken
My Code
DocsForTopicModel=StringDF.groupby(['DocID'],as_index=False).agg(lambda x : ' '.join(x))
My Output
DocID LessStopWords
0 010b158d-8c0b-49ad-9340-774893e4f62f DocID LessStopWords
1 02874037-416d-4b91-8e2d-1a288b8c3a7b DocID LessStopWords
2 05b9ea7b-b5f0-4757-854c-b303a295f606 DocID LessStopWords
3 06f87756-4dbe-4199-a8e2-b504451e823a DocID LessStopWords
4 070bd4d1-6830-447e-9042-12c6def18822 DocID LessStopWords
My Hoped For Output
DocID LessStopWords
0 010b158d-8c0b-49ad-9340-774893e4f62f judgment of the court chamber the request proceedings legal context law article 1 directive
1 02874037-416d-4b91-8e2d-1a288b8c3a7b ...