12
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

for文を使わずに、15文字だけでpandasのDataFrameを上下反転させる

Posted at

目標

こんな感じで日付が新しい順で入っているデータを日付順で上下反転させて取り扱いたくて、ぐぐった。日本語ソースで簡単に出てこなかったのでもちろん英語で調べざるを得なかった。。。ソースはこちら

運営しているブログはこちら:努力1mm

2016-06-13  16910  16910  16620  16630   213980    16630
2016-06-10  17280  17280  17090  17180    67270    17180
2016-06-09  17340  17390  17190  17270    59900    17270
2016-06-08  17320  17440  17180  17440    56410    17440
2016-06-07  17250  17310  17140  17260    50000    17260
...           ...    ...    ...    ...      ...      ...
2001-08-24  11200  11250  11090  11180   227960    11180
2001-08-23  11430  11430  11100  11180   228950    11180
2001-08-22  11190  11490  11170  11380   184270    11380
2001-08-21  11320  11370  11150  11280   135740    11280
2001-08-20  11300  11350  11200  11270   170890    11270
2001-08-20  11300  11350  11200  11270   170890    11270
2001-08-21  11320  11370  11150  11280   135740    11280
2001-08-22  11190  11490  11170  11380   184270    11380
2001-08-23  11430  11430  11100  11180   228950    11180
2001-08-24  11200  11250  11090  11180   227960    11180
...           ...    ...    ...    ...      ...      ...
2016-06-15  16390  16590  16330  16520    92530    16520
2016-06-16  16460  16500  15970  16010   157200    16010
2016-06-17  16240  16350  16160  16180   140830    16180
2016-06-20  16460  16630  16450  16540    84920    16540
2016-06-21  16450  16800  16350  16760   136000    16760

反転させるためのコード

data.iloc[::-1]

で終わり、笑 実際に叩いてみたら上下入れ替わってびっくりした
相変わらず iloclocとかその辺の仕組みがよく分からない、笑

12
7
2

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?