[Python] How can I compare two pandas DataFrames with object-type columns, with a numeric...

Discussão em 'Python' iniciado por Stack, Agosto 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have two pandas dataframes: One assembled manually in Python, the other imported from a dashboard's .csv output.

    All columns in both dataframes are objects, and look like this:

    2020 2021 2022 2023
    0.441 0.554 0.113 0.445
    0.233 0.215 0.225 0.115
    Fifty (50/99) One (1/99) Ten (10/99) Eleven (11/99)
    0.554 0.111 0.545 0.577
    Africa Europe Africa Asia

    y_2020 = [0.441, 0.233, 'Fifty (50/99)', 0.554, 'Africa']
    y_2021 = [0.554, 0.215, 'One (1/99)', 0.111, 'Europe']
    y_2022 = [0.113, 0.225, 'Ten (10/99)', 0.545, 'Africa']
    y_2023 = [0.445, 0.115, 'Eleven (11/99)', 0.577, 'Asia']


    df1 = pd.DataFrame(
    data = list(zip(y_2020, y_2021 , y_2022, y_2023)),
    columns = ['2020', '2021', '2022', '2023'])

    df2 = df1.copy()



    I want to check if the dashboard is producing accurate figures by comparing the contents of both outputs. I'd like to check the numeric values are within a 0.1 tolerance of each other. Strings must be exact.

    I'm struggling with .equals() and .compare() because of the string/integer mix and wanting a 0.1 tolerance.

    Thanks.

    Continue reading...

Compartilhe esta Página