Remove rows with duplicate indices (Pandas DataFrame and TimeSeries)

后端 未结 6 913
我寻月下人不归
我寻月下人不归 2020-11-22 14:31

I\'m reading some automated weather data from the web. The observations occur every 5 minutes and are compiled into monthly files for each weather station. Once I\'m done pa

6条回答
  •  春和景丽
    2020-11-22 15:31

    Unfortunately, I don't think Pandas allows one to drop dups off the indices. I would suggest the following:

    df3 = df3.reset_index() # makes date column part of your data
    df3.columns = ['timestamp','A','B','rownum'] # set names
    df3 = df3.drop_duplicates('timestamp',take_last=True).set_index('timestamp') #done!
    

提交回复
热议问题