Python 类型为'的参数;numpy.int64';这是不可容忍的
我已经检查了论坛,但似乎无法使这项工作。我有一个CSV文件,共有1300行。其中一列是标题ID。ID列是一个六位数的数字。当我尝试使用此代码查找特定号码时:Python 类型为'的参数;numpy.int64';这是不可容忍的,python,pandas,Python,Pandas,我已经检查了论坛,但似乎无法使这项工作。我有一个CSV文件,共有1300行。其中一列是标题ID。ID列是一个六位数的数字。当我尝试使用此代码查找特定号码时: df[df['ID'].map(lambda ID: "342270" in ID)] 我从追踪中得到以下信息 TypeError Traceback (most recent call last) <ipython-input-12-dbef5
df[df['ID'].map(lambda ID: "342270" in ID)]
我从追踪中得到以下信息
TypeError Traceback (most recent call last)
<ipython-input-12-dbef5920f124> in <module>()
----> 1 df[df['ID'].map(lambda ID: "342270" in ID)]
/home/noteleks/anaconda3/lib/python3.5/site-packages/pandas /core/series.py in map(self, arg, na_action)
2119 index=self.index).__finalize__(self)
2120 else:
-> 2121 mapped = map_f(values, arg)
2122 return self._constructor(mapped,
2123 index=self.index).__finalize__(self)
pandas/src/inference.pyx in pandas.lib.map_infer (pandas/lib.c:63043)()
<ipython-input-12-dbef5920f124> in <lambda>(ID)
----> 1 df[df['ID'].map(lambda ID: "342270" in ID)]
TypeError: argument of type 'numpy.int64' is not iterable
TypeError回溯(最近一次调用)
在()
---->1 df[df['ID'].map(lambda ID:“342270”在ID中)]
/地图中的home/noteleks/anaconda3/lib/python3.5/site-packages/pandas/core/series.py(self、arg、na_动作)
2119 index=self.index.\uuuu最终确定\uuuuu(self)
2120其他:
->2121 mapped=map_f(值,arg)
2122返回自构造函数(已映射,
2123 index=self.index.\uuuu最终确定\uuuuu(self)
pandas.lib.map_infere(pandas/lib.c:63043)()中的pandas/src/inference.pyx
输入(ID)
---->1 df[df['ID'].map(lambda ID:“342270”在ID中)]
TypeError:类型为“numpy.int64”的参数不可编辑
当您在ID中使用时,实际上是在对ID
进行迭代,查看其中是否有任何项与中之前的项相等。您是否希望在此处使用str()
:
df[df['ID'].map(lambda ID: "342270" in str(ID)]
或者您想看看ID
是否与342270
相同:
df[df['ID'].map(lambda ID: ID == 342270)]
在这种情况下,不需要lambda函数:
df[df.ID == 342270]
应该做这个把戏试试这个df[df.ID==342270]
取而代之谢谢你,我会把它放在我的工具箱里。