1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Merge the duplicate rows on multiple column?

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    Sample Input:

    DID FIRST NAME MIDDLE NAME LAST NAME STREET CITY STATE ZIP DOB PIN TIN
    CRA0012347129 John JR Nan Doe Nan Nan Nan 1124.0 02-07-2020 12345678998765432 268869162.0
    CRA0012347152 John Nan Doe Nan Nan Nan 201.0 12-12-2020 12261986 Nan
    CRA0012347286 John Nan Doe Nan Nan Nan Nan Nan 12261986 268869162.0


    Instructions: 1 You have to merge duplicate records (rows) using PIN and TIN columns as primary keys. Example given below. 2 You can use DOB column as secondary key. Think of concatenating this column with other columns to create a secondary key. 3 Ensure all 'similar' records (rows) are merged based on the above two points.

    Expected Output:

    DID FIRST NAME MIDDLE NAME LAST NAME STREET CITY STATE ZIP
    CRA0012347129, CRA0012347152, CRA0012347286 John JR, John NaN Doe NaN NaN NaN 1124, 201

    DOB PIN TIN
    02/07/2020, 12/12/2020 12345678998765432,'012261986 '268869162

    Continue reading...

Compartilhe esta Página