假设我有两个Python Pandas数据框:
"StudentRoster Jan-1":
id Name score isEnrolled Comment
111 Jack 2.17 True He was late to class
112 Nick 1.11 False Graduated
113 Zoe 4.12 True
"StudentRoster Jan-2":
id Name score isEnrolled Comment
111 Jack 2.17 True He was late to class
112 Nick 1.21 False Graduated
113 Zoe 4.12 False On vacation
我的目标是输出一个 HTML 表格,该表格:
- 识别已更改的行(可以是整数、浮点数、布尔值或字符串)
输出具有相同、OLD 和 NEW 值的行(最好以 HTML 表格的形式),以便使用者清楚地看到两个数据帧之间的差异:
"StudentRoster Difference Jan-1 - Jan-2":
id Name score isEnrolled Comment
112 Nick was 1.11| now 1.21 False Graduated
113 Zoe 4.12 was True | now False was "" | now "On vacation"
我可以逐行逐列进行比较,但是否有更简便的方法呢?
df.compare
的函数来完成这个操作。 - cs95