LoginSignup
11
7

More than 3 years have passed since last update.

'DataFrame' object has no attribute 'ix'の解決法

Last updated at Posted at 2021-02-25

はじめに

オライリージャパンの「Pythonではじめる機械学習」の4章のp.210の以下のコードを打ち込んだ時,エラーが発生しました.

features = data_dummies.ix[:,"age":"occupation_ Transport-moving"]
#NumPy配列を取り出す
X = features.values
y = data_dummies["income_ >50K"].values
print("X.shape: {} y.shape: {}".format(X.shape,y.shape))

エラー内容

'DataFrame' object has no attribute 'ix'

解決法

調べてみると,2020年2月に導入されたpandas-1.0.0で,以前バージョン0.7.3まで使用できたDataFrameの.ixが廃止されたそうです.
しかし,代わりにlocを用いることで解決できます.

features = data_dummies.loc[:,"age":"occupation_ Transport-moving"]
#NumPy配列を取り出す
X = features.values
y = data_dummies["income_ >50K"].values
print("X.shape: {} y.shape: {}".format(X.shape,y.shape))

loc使用後

X.shape: (32561, 44) y.shape: (32561,)

エラーが消えました.

参考

https://ebcrpa.jamstec.go.jp/~yyousuke/matplotlib/info.html ,2021/2/25参照

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