LoginSignup
33
18

More than 5 years have passed since last update.

pandasのデータフレームの列を入れ替える

Last updated at Posted at 2015-12-30

pandasのDataFrameの列を入れ替えるには、ixで列名を入れ替え後の順番に指定してあげましょう。

df
'''
これがデータフレームdfだとします
    a   b   c   
A   0   1   2   
S   5   6   7   
'''

#このコードを実行すると…
df.ix[:,['a','c','b']]
'''
以下のようになります
    a   c   b   
A   0   2   1
S   5   7   6
'''

以上でpandas初心者の私が躓いたポイントの解説でした。

追記:
もちろん列のインデックスを数値で指定しても大丈夫です。

33
18
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
33
18