คุณสามารถใช้ np.array_equal
เพื่อตรวจสอบค่าได้ อย่างไรก็ตาม การเรียงลำดับมีความสำคัญ ดังนั้นในตัวอย่างของคุณ คุณจะต้องเรียงลำดับตามดัชนีก่อน
In [11]: df1
Out[11]:
A B
0 87 54
1 87 75
2 87 22
3 87 69
In [12]: df2
Out[12]:
A B
418 87 69
107 87 54
108 87 75
250 87 22
In [13]: df3 = df2.sort()
In [14]: df3
Out[14]:
A B
107 87 54
108 87 75
250 87 22
418 87 69
In [15]: np.array_equal(df1, df3)
Out[15]: True
หมายเหตุ: คุณไม่สามารถเปรียบเทียบ df1 และ df2 ได้เนื่องจากมีดัชนีต่างกัน:
In [21]: df1 == df2
ValueError: Can only compare identically-labeled DataFrame object
คุณสามารถรีเซ็ตดัชนีได้ แต่โปรดทราบว่าอาจมีข้อยกเว้นเกิดขึ้นได้ด้วยเหตุผลดังกล่าว:
In [22]: df3.reset_index(drop=True)
Out[22]:
A B
0 87 54
1 87 75
2 87 22
3 87 69
In [23]: np.all(df1 == df3.reset_index(drop=True))
Out[23]: True
อีกทางเลือกหนึ่งคือลองและยกเว้นบล็อกประมาณ assert_frame_equals
:
In [24]: pd.util.testing.assert_frame_equal(df1, df3.reset_index(drop=True))
เช่นเดียวกับในคำตอบที่เกี่ยวข้องนี้
ตามที่ Jeff ชี้ให้เห็นว่าคุณสามารถใช้ .equals ซึ่งทำสิ่งนี้:
In [25]: df1.equals(df3.reset_index(drop=True))
Out[25]: True
person
Andy Hayden
schedule
19.10.2015