0
0

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.

表の結合にconcatを使ったのですがうまくいきません

Posted at

(例)pythonでアヤメの分類のプログラムを作っています。
表を作る作業中に、以下のエラーメッセージが発生しました。

発生している問題・エラーメッセージ
TypeError Traceback (most recent call last)
in
17
18 import pandas
---> 19 iris_test=concat([tt_ind,X_test,y_test],axis=0)
20 print(iris_test)

~\Anaconda3\lib\site-packages\pandas\core\reshape\concat.py in concat(objs, axis, join, join_axes, ignore_index, keys, levels, names, verify_integrity, sort, copy)
253 verify_integrity=verify_integrity,
254 copy=copy,
--> 255 sort=sort,
256 )
257

~\Anaconda3\lib\site-packages\pandas\core\reshape\concat.py in init(self, objs, axis, join, join_axes, keys, levels, names, ignore_index, verify_integrity, copy, sort)
330 " only Series and DataFrame objs are valid".format(type(obj))
331 )
--> 332 raise TypeError(msg)
333
334 # consolidate

TypeError: cannot concatenate object of type ''; only Series and DataFrame objs are valid

該当のソースコード
Python

from sklearn import datasets
from sklearn.model_selection import ShuffleSplit as SS
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score as a_score

アヤメのデータセットを読み込む
iris=datasets.load_iris()
X=iris.data
y=iris.target

データを分割するインデックスを作る
iris_ss=SS(test_size=0.3)
tr_ind,tt_ind = next(iris_ss.split(X))

データを学習データと評価データに分割する
X_train,X_test,y_train,y_test=X[tr_ind],X[tt_ind],y[tr_ind],y[tt_ind]

import pandas
iris_test=concat([tt_ind,X_test,y_test],axis=1)
print(iris_test)

試したこと
他のメソッドもいろいろ試しましたがうまくいきません。上のエラーに対する対策がもっとも根本的ではないかと思いました。

補足情報(FW/ツールのバージョンなど)
markdawnがまだ使えなくてすみません。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?