-1

I have df like this:

df1:
    PL IN
    22 NE22
    22 NE22
    22 NE22
    33 DE33
    33 DE33
    66 NL66
    66 NL66
    66 NL66

I need to save csv with only unique value so the result should be:

    22 NE22
    33 DE33
    66 NL66

I know .unique() method but it works only on Series (?) I need to pic 2 col. Can someone give me an advice?

martin
  • 1,145
  • 1
  • 7
  • 24
  • 1
    Usel `df.drop_duplicates(['PL', 'IN'])` – Erfan Jun 28 '19 at 21:18
  • @RenéHöhle Thanks for the suggestion, but in that post is list hardcoding and only loops in core python. I hoped to answer as Erfan one. I didn't know that func. Thank U! – martin Jun 28 '19 at 21:33

1 Answers1

2

Drop the duplicates then write to csv.

df1 = df1.drop_duplicates(subset=['PL', 'IN'], keep='first')
df1.to_csv('my_unique_csv.csv', index=False)
d_kennetz
  • 5,219
  • 5
  • 21
  • 44