繁体   English   中英

TypeError:“ int”类型的参数不可迭代

[英]TypeError: argument of type 'int' is not iterable

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

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

您在熊猫中发现了一个错误; 您在具有单一集索引的数据帧上使用reset_index() ,而熊猫索引的版本介于0.19.2和0.20.1之间。 这是问题#16263

在v0.19.2和v0.20.1之间,DataFrame.reset_index的行为DataFrame.reset_index更改。 使用单个集合索引:

  • 它不会尝试保留该列(实际上使drop = True始终处于打开状态)
  • level = int不再起作用(可迭代项起作用)

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

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

您正在将level传递为值为0的变量。 然后,您使用in关键字查看i是否in level变量中。 in关键字的基本含义是“查看此列表/集合/字符串/所拥有的内容,看看其中是否包含此其他变量”。 Python尝试查看您的level变量,发现它是一个int ,并且不知道要做什么,因为您无法查看int 它只是自己的东西,而不是其他东西的容器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM