我正在从数据框的列中写入单个条目
2011100101 被解释为 2011 年 10 月 1 日凌晨 1 点。
我希望它的格式更改为 YYYY-Mmm-dd HH
train['date1']=datetime.strptime(train['ID'], '%Y%m%d%H')
Run Code Online (Sandbox Code Playgroud)
但得到一个错误 TypeError: strptime() 参数 1 必须是字符串,而不是系列
如何更改单个列中整个条目所需的格式?
下面是变量的前 5 行,我使用 KMeans 来找到最佳的簇数-
store_code PinCode sale_price_after_promo
0 2655 453441.0 55.00
1 2655 999999.0 30.00
2 2655 400064.0 418.95
3 2615 400099.0 70.00
4 2655 474001.0 34.20
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误 -
OverflowError Traceback (most recent call last)
<ipython-input-62-3802a2b79f71> in <module>()
2 for i in range(0,11):
3 kmeans=KMeans(n_clusters=i, init='k-means++', random_state=42)
----> 4 kmeans.fit(X)
5 wcss.append(kmeans.inertia_)
6 plt.plot(range(1, 11), wcss)
OverflowError: cannot convert float infinity to integer
Run Code Online (Sandbox Code Playgroud)
即使我尝试使用各种变量组合但仍然出现相同的错误,如何摆脱这个错误?