0

So I have this pandas dataframe coded in a python jupyter notebook as an example:


col1|col2|col3|col4
-------------------
"a" |"b" |0   |"d"
"a" |"b" |1   |"e"

I am trying to combine rows into one that has the exact same values in col1 and col2, and concatenate col4 values. This would be the intended result:


col1|col2|col3|col4
-------------------
"a" |"b" |0   |"de"

I have tried using the pandas aggregate function but I am still not getting what I want by concatenating string from col4.

Thank you so much guys for your help!

2
  • 2
    df.groupby(['col1','col2'], as_index=False).agg({'col3':'first', 'col4':''.join}) Commented Feb 17, 2023 at 6:25
  • 2
    Hold on I will try it thank you I will update you asap Commented Feb 17, 2023 at 6:26

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.