检查列中的值是否为整数并返回true
我有一个带有数量
列的数据框。如何检查该列中的哪些值是整数?
我尝试过
if df['quantity'].map(type) == int:
True
else:
item_no = df['item_number'].tolist()
print(item_no)
,这给了我以下valueerror:系列的真实价值是模棱两可的。使用A.Empty,A.Bool(),A.Item(),A.Any()或A.all()。
理想情况下,我希望输出成为项目编号的列表数量不是整数。
I have a dataframe with a quantity
column. How do I check which values in that column are integers?
I have tried
if df['quantity'].map(type) == int:
True
else:
item_no = df['item_number'].tolist()
print(item_no)
which gives me the following ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Ideally, I would like the output to be a list of the item numbers where the quantity is not an integer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果要检查列中是否有python
int
s,请尝试以下操作:If you want to check if there are any Python
int
s in your column, try this:假设您只需要值的索引,则以下应该足够
df.index [(df [Quantity']。map(type)== int)]。tolist(tolist()
Assuming you just want the indices where the value is an int, the following should suffice
df.index[(df['quantity'].map(type)==int)].tolist()
如果要识别可以使用的非整数:
或
用于非数字:
If you want to identify the non integers you can use:
Or
Or for non numbers:
以下代码返回“数量”列不包含整数的项目编号列表
The following code returns a list of the item numbers for where the 'quantity' column does not contain an integer