0
1

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 1 year has passed since last update.

dataframeに、date型やobject型のデータがある際の、正規化をする際の修正点

Last updated at Posted at 2022-03-29

問題点
dataframeに、date型のデータがあると、エラーが発生する
image.png
エラー表示
image.png
解決策
1.データ型を確認
image.png
2.time(datetime)をindexにする
image.png
3.エラー表示(could not convert string to float: 'NE')
image.png

4.ラベルエンコーディング

# ラベルエンコーディング(LabelEncoder)
from sklearn.preprocessing import LabelEncoder
label_train = train.copy()
label_valid = val.copy()

s = (train.dtypes == 'object')
object_cols = list(s[s].index)
#カテゴリデータを使用して各列にラベルエンコーダを適用します
label_encoder = LabelEncoder()
for col in object_cols:
    train[col] = label_encoder.fit_transform(train[col])
    val[col] = label_encoder.transform(val[col])

image.png

image.png

'

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?