Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18995

Concatenate the rows of each column being grouped by identify

$
0
0

Welcome Help.

I would like to merge multiple rows of each ID of a dataframe into a single cell, Below is input format:

enter image description here

I have the following list of columns and Dataframe in pandas respectively

dict1 = {'ID': ['6610', '6610', '6610', '6620', '6620', '7540', '7540'],'NEW_ID': ['6615','6615','6615','','',  nan,  nan],'OLD_PRICE': [17.22, 17.9, 17.22, 27.49, 20.42, 30.73, 29.55],'NEW_PRICE': [17.22, 17.22, 27.49, 18.99, 27.49, 29.55, 27.49],'LABEL': ['  NaN1', '  NaN2', '  NaN4', nan, '  Na', 'A', 'B']}df = pd.DataFrame(dict1)

Expected output:

enter image description here


Viewing all articles
Browse latest Browse all 18995

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>