You also need to be careful to create a copy of the DataFrame, otherwise the csvdata_old will be updated with csvdata (since it points to the same object):

csvdata_old = csvdata.copy()

To check whether they are equal, you can use assert_frame_equal as in this answer:

from pandas.util.testing import assert_frame_equal
assert_frame_equal(csvdata, csvdata_old)

You can wrap this in a function with something like:

try:
    assert_frame_equal(csvdata, csvdata_old)
    return True
except:  # appeantly AssertionError doesn't catch all
    return False

There was discussion of a better way...

Answer from Andy Hayden on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.equals.html
pandas.DataFrame.equals — pandas 3.0.1 documentation
This function allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements. NaNs in the same location are considered equal.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_equals.asp
Pandas DataFrame equals() Method
Pandas Editor Pandas Quiz Pandas Exercises Pandas Syllabus Pandas Study Plan Pandas Certificate · DataFrames Reference · ❮ DataFrame Reference · Check if two DataFrames ar equal: import pandas as pd data1 = { "name": ["Sally", "Mary", "John", "Mary"], "age": [50, 40, 30, 40] } df1 = pd.DataFrame(data) data2 = { "name": ["Sally", "Mary", "John", "Mary"], "age": [50, 40, 30, 40] } df2 = pd.DataFrame(data) print(df1.equals(df2)) Try it Yourself » ·
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.Index.equals.html
pandas.Index.equals — pandas 2.3.3 documentation - PyData |
>>> idx1 = pd.Index([1, 2, 3]) >>> idx1 Index([1, 2, 3], dtype='int64') >>> idx1.equals(pd.Index([1, 2, 3])) True
🌐
Medium
medium.com › @amit25173 › what-is-pandas-equals-and-when-to-use-it-8030322628d5
What is pandas.equals() and When to Use It? | by Amit Yadav | Medium
March 6, 2025 - By resetting the index, we align both DataFrames before checking equality. ... This might surprise you: Unlike standard Python comparisons, pandas.equals() treats NaN values as equal!
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas dataframe equals() method
Pandas DataFrame equals() Method - Spark By {Examples}
July 29, 2024 - The equals() method in Pandas is used to compare two DataFrame objects to check if they are exactly equal.
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-equals.php
Pandas DataFrame: equals() function - w3resource
August 19, 2022 - Pandas DataFrame - equals() function: The equals() function is used to test whether two objects contain the same elements.
Find elsewhere
🌐
Saturn Cloud
saturncloud.io › blog › how-to-confirm-equality-of-two-pandas-dataframes
How to Confirm Equality of Two Pandas DataFrames | Saturn Cloud Blog
December 28, 2023 - In this example, we create two identical DataFrames, df1 and df2, and compare them using the equals() method. Since the DataFrames are identical, the output will be "The two DataFrames are equal". Another method of comparing two pandas DataFrames is to use the compare() method.
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.testing.assert_frame_equal.html
pandas.testing.assert_frame_equal — pandas 3.0.1 documentation
pandas.testing.assert_frame_equal(left, right, check_dtype=True, check_index_type='equiv', check_column_type='equiv', check_frame_type=True, check_names=True, by_blocks=False, check_exact=<no_default>, check_datetimelike_compat=False, check_categorical=True, check_like=False, check_freq=True, check_flags=True, rtol=<no_default>, atol=<no_default>, obj='DataFrame')[source]# Check that left and right DataFrame are equal.
🌐
Medium
medium.com › @tzhaonj › comparing-dataframes-in-pandas-equal-and-compare-9648e8441c5c
Comparing dataframes in Pandas .equal and .compare | by Tim Zhao | Medium
July 30, 2024 - Two powerful methods in Pandas, equals() and compare(), are designed for such tasks. While equals() checks for complete equality between two DataFrames, compare() helps pinpoint specific differences.
🌐
Skytowner
skytowner.com › explore › pandas_dataframe_equals_method
Pandas DataFrame | equals method with Examples
April 28, 2016 - Master the mathematics behind data science with 100+ top-tier guides Start your free 7-days trial now! Pandas DataFrame.equals(~) checks whether two DataFrames are identical, that is, all their respective values, column labels and index names are equal, and have the same data type.
🌐
w3resource
w3resource.com › pandas › series › series-equals.php
Pandas Series: equals() function - w3resource
September 15, 2022 - The equals() function is used to test whether two Pandas objects contain the same elements.
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.20 › generated › pandas.DataFrame.equals.html
pandas.DataFrame.equals — pandas 0.20.3 documentation
Determines if two NDFrame objects contain the same elements. NaNs in the same location are considered equal. index · modules | next | previous | pandas 0.20.3 documentation » · API Reference » ·
🌐
TutorialsPoint
tutorialspoint.com › article › how-does-the-pandas-series-equals-method-handle-the-null-values
How does the pandas series.equals() method handle the null values?
The fundamental operation of the pandas series.equals() method is used to compare two series for equality. it returns True if the two series have the same elements and shape, and returns False if the two series are unequal.
🌐
Data Science Parichay
datascienceparichay.com › home › blog › compare two dataframes for equality in pandas
Compare Two DataFrames for Equality in Pandas - Data Science Parichay
October 27, 2023 - The pandas dataframe function equals() is used to compare two dataframes for equality. It returns True if the two dataframes have the same shape and elements. For two dataframes to be equal, the elements should have the same dtype.
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.testing.assert_frame_equal.html
pandas.testing.assert_frame_equal — pandas 3.0.0rc1+92.g17b66cc0ad documentation
pandas.testing.assert_frame_equal(left, right, check_dtype=True, check_index_type='equiv', check_column_type='equiv', check_frame_type=True, check_names=True, by_blocks=False, check_exact=<no_default>, check_datetimelike_compat=False, check_categorical=True, check_like=False, check_freq=True, check_flags=True, rtol=<no_default>, atol=<no_default>, obj='DataFrame')[source]# Check that left and right DataFrame are equal.
🌐
Studytonight
studytonight.com › pandas › pandas-dataframe-equals-method
Pandas DataFrame equals() Method - Studytonight
Python pandas DataFrame.equals() method.This method allows two Series or DataFrames to be compared against each other to see if they have the same shape and elements.