db_data_df = data1['data']
data_df = data2['data2']
print(db_data_df.equals(data_df))
I have two dataframes. I am checking if they are equal or not. They are. but instead of giving true, it is saying false. why?
If I turn the values of both df into dict this is the result I get.
{'data': {0: 0.88, 1: 0.976, 2: 1.072, 3: 1.195, 4: 1.295}}
{0: 0.88, 1: 0.976, 2: 1.072, 3: 1.195, 4: 1.295}
CodePudding user response:
Try to use np.close
:
import numpy as np
np.isclose(data1['data'], data2['data2']).all()
CodePudding user response:
It seems data1['data'] is series, while data2['data2'] is list. You can convert data2['data2'] to series and then use the same method that you used.
Try:
data1=pd.DataFrame.from_dict({'data': {0: 0.88, 1: 0.976, 2: 1.072, 3: 1.195, 4: 1.295}})
data2['data2']=[0.88,0.976,1.072,1.195,1.295]
db_data_df = data1['data']
data_df = pd.Series(data2['data2'])
print(db_data_df.equals(data_df))
#True