0

i am a newbie, slowly learning... i have a unique dataframe as shown below:

               time
index
 1            8:51 am 
 1            8:51 am
 1            8:51 am
 2            8:52 am
 2            8:52 am
 3            8:53 am
 3            8:53 am
 3            8:53 am

i want to be able to combine the dataframe and input the index in one row only as shown below:

                time
index
 1            8:51 am 
 2            8:52 am
 3            8:53 am
  • Does this answer your question? [Drop all duplicate rows in Python Pandas](https://stackoverflow.com/questions/23667369/drop-all-duplicate-rows-in-python-pandas) – RichieV Jul 26 '20 at 03:44

3 Answers3

2

Try with

df = df.groupby(level=0).head(1)
BENY
  • 317,841
  • 20
  • 164
  • 234
0

Nothing looks unique there, that just seems to be whole duplicate rows (unless timestamps can be different for same index number)

Df.drop_duplicates function is what you’re looking for.

You can also use this function even if timestamp can be different by just running it over a selected column( index) and argument “first” or “last” will keep first or last of those timestamps.

0
data.drop_duplicates(subset ="time",   keep = False, inplace = True)

This should return only the rows of the dataframe containing unique values in the subset column mentioned.

Ch3steR
  • 20,090
  • 4
  • 28
  • 58
tehem
  • 45
  • 1
  • 5