【问题标题】:Read two SQL using two different dataframe and compare the two resultant datasets [closed]使用两个不同的数据框读取两个 SQL 并比较两个结果数据集 [关闭]
【发布时间】:2020-09-08 11:13:04
【问题描述】:

使用两个不同的数据框读取两个 SQL(两个 SQL 查询都有 7 个相似的列结构),并比较两个结果数据集是否匹配。 我曾尝试使用 .equals 运算符,但我得到了:

ValueError: too many values to unpack (expected 2)

我正在使用 Python Pandas 编写代码。让我知道如果这样的事情是可能的,我是 Python 的新手,任何帮助或建议将不胜感激。 提前致谢。

【问题讨论】:

  • 能否将整个代码添加到您的问题中?

标签: python sql pandas dataframe


【解决方案1】:

您可以像这样检查 DataFrame 的(确切)equality:

import pandas as pd

df1 = pd.DataFrame({1: [20], 2: [30]})  # here would be your first sql-query

df2 = pd.DataFrame({1: [20], 2: [30]})  # here would be your second sql-query

df1.equals(df2)  # results in True/False

【讨论】:

    猜你喜欢
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2011-07-30
    • 1970-01-01
    • 2017-01-14
    • 2015-01-02
    • 2022-01-23
    • 1970-01-01
    相关资源
    最近更新 更多