gpt4 book ai didi

python - 类型错误 : argument of type 'int' is not iterable

转载 作者:行者123 更新时间:2023-11-28 21:03:22 25 4
gpt4 key购买 nike

我试图从索引中为集群训练数据创建一个唯一标识符变量,以便与集群分配变量合并

clus_train.reset_index(level=0, inplace=True)

它抛出一个错误说

TypeError                                 Traceback (most recent call last)
<ipython-input-41-d0d098349dbc> in <module>()
1 # create a unique identifier variable from the index for the
2 # cluster training data to merge with the cluster assignment variable
----> 3 clus_train.reset_index(level=0, inplace=True)

C:\Users\3016205\AppData\Local\Continuum\Anaconda3\lib\site-
packages\pandas\core\frame.py in reset_index(self, level, drop, inplace,
col_level, col_fill)
3053 # to ndarray and maybe infer different dtype
3054 level_values = _maybe_casted_values(lev, lab)
-> 3055 if level is None or i in level:
3056 new_obj.insert(0, name, level_values)
3057

TypeError: argument of type 'int' is not iterable

你能帮忙解决一下吗?我正在使用 Python 3.x

最佳答案

您在 Pandas 中遇到了一个错误;您在具有单集索引的数据帧上使用 reset_index(),Pandas 版本介于 0.19.2 和 0.20.1 之间。这是 issue #16263 :

between v0.19.2 and v0.20.1, the behavior of DataFrame.reset_index changed. With a single set index:

  • It does not attempt to keep the column (essentially making drop=True always on)
  • level=int no longer works (iterables work)

将 Pandas 升级到 0.20.2 或更新版本。

如错误报告所述,临时解决方法是使用 level=[0]

关于python - 类型错误 : argument of type 'int' is not iterable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46534093/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com