[英]Pandas list comparison giving value error
I have a dataframe I generate by using我有一个 dataframe 我使用生成
df = qr_actions.get_pandas_df(query)
and then generate a list of the rows using rows = [r[1] for r in df.iterrows()]
and am trying to compare it to another list of rows I generate using the same method by doing (rows1 == rows2).all()
, but keep getting the error然后使用
rows = [r[1] for r in df.iterrows()]
生成行列表,并尝试将其与我使用相同方法生成的另一个行列表进行比较(rows1 == rows2).all()
,但不断收到错误
Name: 0, dtype: bool
def __nonzero__(self):
raise ValueError("The truth value of a {0} is ambiguous. "
"Use a.empty, a.bool(), a.item(), a.any() or a.all()."
> .format(self.__class__.__name__))
E ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
/usr/local/lib/python2.7/dist-packages/pandas/core/generic.py:892: ValueError
How can I do this?我怎样才能做到这一点? When I try to use pandas series equality functions I get errors because my objects are lists, but doing rows1 == rows2 alone gives me the output above.
当我尝试使用 pandas 系列相等函数时,我得到错误,因为我的对象是列表,但是单独执行 rows1 == rows2 会给我上面的 output。 How can I solve this?
我该如何解决这个问题?
=================================================== ==================================================== =
Alternatively, I know my two rows are both或者,我知道我的两行都是
[a 1
Name: 0, dtype: int64]
How can I compare them to assert true for testing purposes?为了测试目的,我如何比较它们以断言为真?
Your rows
is a list and a operation rows1 == rows2
will return a boolean after which you can't apply all
attribute.您的
rows
是一个列表,操作rows1 == rows2
将返回 boolean ,之后您无法应用all
属性。 Converting your rows to pd.Series
will solve the issue:将您的行转换为
pd.Series
将解决该问题:
rows = pd.Series([r[1] for r in dftest.iterrows()])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.