LoginSignup
3
3

More than 5 years have passed since last update.

pandasのdataframeでindexを振り直す方法

Last updated at Posted at 2017-04-25

dataframeを行削除や結合など操作しているうちにindexが乱れる場合がある.
この場合にindexを0から振り直したい場合はreset_index(drop=True)を使う.

reset_index.py
    rssi_data = rssi_data.reset_index(drop=True)

before.py
 print window_data.head()
               t   dist(8)   dist(9)  dist(10)  dist(11)  dist(12)
13  12:55:26.600  2.362109  2.369736  2.031889  1.240509  0.860399
14  12:55:26.800  2.336146  2.385064  1.986095  1.210598  0.847227
15  12:55:27.000  2.312065  2.412682  1.936422  1.180321  0.835603
16  12:55:27.200  2.289813  2.441181  1.891472  1.154516  0.823569
17  12:55:27.400  2.269342  2.470586  1.850973  1.132922  0.811148

index振り直し

after.py
 window_data = window_data.reset_index(drop=True)
 print window_data.head()
              t   dist(8)   dist(9)  dist(10)  dist(11)  dist(12)
0  12:55:26.600  2.362109  2.369736  2.031889  1.240509  0.860399
1  12:55:26.800  2.336146  2.385064  1.986095  1.210598  0.847227
2  12:55:27.000  2.312065  2.412682  1.936422  1.180321  0.835603
3  12:55:27.200  2.289813  2.441181  1.891472  1.154516  0.823569
4  12:55:27.400  2.269342  2.470586  1.850973  1.132922  0.811148
3
3
0

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
3
3