Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Create 2 DataFrame from the existing DataFrame

I would like to create a 2 dataframe, df1 and df2 from the old dataframe. df1 should have only one name and no duplicates. df2 should have the remaining duplicate names.

My input:
df:

Name Age
Amy 24
Amy 34
jack 66
mo 76
mo 88
mo 98
linn 33

Output, df1:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Name Age
Amy 24
Jack 66
mo 76
linn 33

Output, df2:

Name Age
Amy 34
mo 88
mo 98

>Solution :

  • No duplicates:
    df1 = df[~df.duplicated('Name')]
  • Duplicates:
    df2 = df[df.duplicated('Name')]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading