1

I found the function compare in the Pandas documentation:

pandas.DataFrame.compare
DataFrame.compare(other, align_axis=1, keep_shape=False, keep_equal=False)

Source

   def New_names(self, df_old, df_new):

    #New records for insert
    df_old_names = set(df_old['name'])
    df_new_names = set(df_new['name'])

    difference = df_new_names - df_old_names
    coincidence = df_old_names - difference

    exit_insert = df_new[df_new['name'].isin(difference)]

    #Check old records

    df_old_names_restrict = df_old[df_new.columns]

    exit_update = df_new.compare(df_old_names_restrict)
    

    return (exit_insert, exit_update)

But it raises the below error:

Traceback (most recent call last):   File
"C:/Users/shulya403/Shulya403_works/all_gid_2/Database/db_insert_pd.py",
line 203, in <module>
 FillDB.Pruducts_to_SQL(df_new=FillDB.df_Products.head(20))   File "C:/Users/shulya403/Shulya403_works/all_gid_2/Database/db_insert_pd.py",
line 184, in Pruducts_to_SQL
    df_select = self.New_names(self.Select_SQL_Products(), df_new)[0]   File
"C:/Users/shulya403/Shulya403_works/all_gid_2/Database/db_insert_pd.py",
line 175, in New_names
    exit_update = df_new.compare(df_old_names_restrict)   File "C:\Users\shulya403\Shulya403_works\all_gid_2\venv\lib\site-packages\pandas\core\generic.py",
line 5274, in __getattr__
    return object.__getattribute__(self, name) AttributeError: 'DataFrame' object has no attribute 'compare'
Emi OB
  • 2,814
  • 3
  • 13
  • 29
shulya403
  • 422
  • 1
  • 6
  • 17
  • Can you post the data and script ? – bigbounty Aug 02 '20 at 13:53
  • What is your `pd.__version__`? It says in docs this method is new in 1.1.0 – RichieV Aug 02 '20 at 14:27
  • 2
    Does this answer your question? [Importing Pandas gives error AttributeError: module 'pandas' has no attribute 'core' in iPython Notebook](https://stackoverflow.com/questions/36521691/importing-pandas-gives-error-attributeerror-module-pandas-has-no-attribute-c) – RichieV Aug 02 '20 at 14:31

1 Answers1

5

What is your pd.__version__? It says in docs this method is new in 1.1.0 – RichieV

YES, it works! The pd.__version__ was 1.0.5

pip install pandas --upgrade, and 'compare' work properly.

Dharman
  • 30,962
  • 25
  • 85
  • 135
shulya403
  • 422
  • 1
  • 6
  • 17