本文介绍了查看DataFrame中是否存在值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python中检查值是否在列表中,您只需执行以下操作即可:
In Python to check if a value is in a list you can simply do the following:
>>>9 in [1,2,3,6,9]
True
我想对Pandas DataFrame做同样的事情,但是不幸的是Pandas无法识别这种符号:
I would like to do the same for a Pandas DataFrame but unfortunately Pandas does not recognise that notation:
>>>import pandas as pd
>>>df = pd.DataFrame([[1,2,3,4],[5,6,7,8]],columns=["a","b","c","d"])
a b c d
0 1 2 3 4
1 5 6 7 8
>>>7 in df
False
我如何使用Pandas DataFrame来实现此目的而又不遍历每列/每行或任何复杂的事物?
How would I achieve this using Pandas DataFrame without iterating through each column/row or anything complicated?
推荐答案
基本上,您必须检查没有模式的矩阵,因此:
Basically you have to check the matrix without the schema, so:
7 in df.values
x in df
检查x
是否在列中:
for x in df:
print x,
out: a b c d
这篇关于查看DataFrame中是否存在值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!