Home > OS >  Create 2 DataFrame from the existing DataFrame
Create 2 DataFrame from the existing DataFrame

Time:12-16

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:

Name Age
Amy 24
Jack 66
mo 76
linn 33

Output, df2:

Name Age
Amy 34
mo 88
mo 98

CodePudding user response:

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