Pandas: Compare two Dataframe and Groupby categorical My Question is about pandas DataFrame, I have two DataFrame both follow the same structure.
df_1:
Index    Text     Category
0        Text 01        1
1        Text 02        1
2        Text 03        1
3        Text 04        1

df_2:
Index    Text     Category
0        Text 05        2
1        Text 02        2
2        Text 09        2
3        Text 04        2

I want to marge both for this purpose I use pd.concat(df_1, df_2) but it simply merge both files, but I want to merge in that manner.
df_merge:
Index    Text     Category
0        Text 01         1
1        Text 02       1,2
2        Text 03         1
3        Text 04       1,2
4        Text 05         2
5        Text 09         2

But I really don't know how to do that.
Try:
Minimum reproducible example:
 A = pd.DataFrame({&quot;Text&quot;:[&quot;01&quot;, &quot;02&quot;,&quot;03&quot;,&quot;04&quot;], &quot;Category&quot;:[1,1,1,1]})
 B = pd.DataFrame({&quot;Text&quot;:[&quot;05&quot;, &quot;02&quot;,&quot;09&quot;,&quot;04&quot;], &quot;Category&quot;:[2,2,2,2]})

 C = pd.concat([A,B], ignore_index= True)

 C.groupby(&quot;Text&quot;).Category.unique().to_frame()

Result: