[Python] Equality of pandas data frames except dtypes

Discussão em 'Python' iniciado por Stack, Janeiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I need to check if two DataFrames are somewhat "equal", but in a looser sense than pandas.DataFrame.equals is implementing it currently.

    I am aware of pandas.testing.assert_frames_equal and I really love it, but now I need it a control flow statement and not for testing. For instance I'd like the following code snippet to output equal:

    df1 = pd.DataFrame([[1]])
    df2 = pd.DataFrame([[1.0]])

    if frames_equals(df1, df2, check_dtypes=False):
    print("equal")
    else:
    print("not equal")


    Is there such a function readily available in the pandas library?

    Note: The question is not about how to build one, but rather if there already is one.

    Continue reading...

Compartilhe esta Página