0

I want to write a code to create a new dataframe based on this old dataframe using panda. dataframe]

In the image, if the field 'Address Line 1' appear more than once, copy that whole row to the new dataframe.
In the case that the field 'Address Line 1' is blank, or appear only once, do not copy.

Notes: Multiple rows entries that has the same 'Address Line 1' might not be right next to each other.

PilouPili
  • 2,601
  • 2
  • 17
  • 31
  • Hi, and welcome! We might be able to help you, if you provide a minimal, complete and verifiable example (https://stackoverflow.com/help/mcve). Please post your dataframe as text, show what you have tried so far and why this didn't fulfill your requirements – Jondiedoop Oct 18 '18 at 06:03

1 Answers1

0

You can use pivot_table in pandas

Gave this a try

df2 = df.pivot_table(index=['Special payee', 'Address Number'],
                                     columns=['Address Line 1', 'Address Line 2'] 
                                     values='Address Line 3',
                                     aggfunc=lambda x: ' '.join(x))

also see this

Umer
  • 1,098
  • 13
  • 31