LoginSignup
19
16

More than 5 years have passed since last update.

pandasのDataFrameでindexが重複した行を削除する

Last updated at Posted at 2016-05-13

ものすごく単純なはずなのに長時間詰まったのでメモ

例えば,

                           data
2016-02-04 01:00:00+00:00   1
2016-02-04 01:00:00+00:00   1                  
2016-02-04 01:30:00+00:00   2
2016-02-04 01:30:00+00:00   2     
2016-02-04 02:00:00+00:00   3

みたいなDataFrame df があった場合

grouped = df.groupby(level=0)  
df2 = grouped.last() 

                           data
2016-02-04 01:00:00+00:00   1                 
2016-02-04 01:30:00+00:00   2   
2016-02-04 02:00:00+00:00   3

が得られる.

19
16
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
19
16