-3
私はCloudera 5.2 VMとpandasを扱います0.18.0 私はデータフレームにkmeansを適用したいと思います。しかし、私はstrの列を持っています。パンダカテゴリ属性を扱う方法
私のデータフレームが
adClicksPerTime.head(n=5)
Out[50]:
timestamp adCategory userId totalAdClicks
0 2016-05-26 15:00:00 automotive 355 1
1 2016-05-26 15:00:00 clothing 1027 1
2 2016-05-26 15:00:00 computers 1821 1
3 2016-05-26 15:00:00 computers 2139 1
4 2016-05-26 15:00:00 electronics 253 1
for col in adClicksPerTime:
print(col)
print(type(adClicksPerTime[col][1]))
timestamp
<class 'pandas.tslib.Timestamp'>
adCategory
<class 'str'>
userId
<class 'numpy.int64'>
totalAdClicks
<class 'numpy.int64'>
私は関数kmeansを実行すると、私は数値コード
adClicksPerTime.adCategory = pd.Categorical.from_array(adClicksPerTime.adCategory)
adClicksPerTime.head(n=5)
Out[54]:
timestamp adCategory userId totalAdClicks
0 2016-05-26 15:00:00 automotive 355 1
1 2016-05-26 15:00:00 clothing 1027 1
2 2016-05-26 15:00:00 computers 1821 1
3 2016-05-26 15:00:00 computers 2139 1
4 2016-05-26 15:00:00 electronics 253 1
for col in adClicksPerTime:
print(col)
print(type(adClicksPerTime[col][1]))
timestamp
<class 'pandas.tslib.Timestamp'>
adCategory
<class 'str'>
userId
<class 'numpy.int64'>
totalAdClicks
<class 'numpy.int64'>
を割り当てるには、カテゴリ型にし、後に自分の文字列を変換しようとしたエラー
ValueError: could not convert string to float: 'automotive'
を取得しています
このstrフィールドにkmeansを適用するにはどうすればよいですか?
k-meansは、**連続**変数に対してのみ設計されています。この種のデータには使用しないでください! –