我想比较两个非常相似的数据帧,一个从json文件加载并重新采样,第二个从CSV文件加载,来自一些更复杂的用例
这些是df1
的第一个值:
page
logging_time
2021-07-04 18:14:47.000 748.0
2021-07-04 18:14:47.100 0.0
2021-07-04 18:14:47.200 0.0
2021-07-04 18:14:47.300 3.0
2021-07-04 18:14:47.400 4.0
[5 rows x 1 columns]
这些是df2
的第二个值:
@timestamp per 100 milliseconds Sum of page
0 2021-04-07 18:14:47.000 748.0
1 2021-04-07 18:14:47.100 0.0
2 2021-04-07 18:14:47.200 0.0
3 2021-04-07 18:14:47.300 3.0
4 2021-04-07 18:14:47.400 4.0
[5 rows x 2 columns]
我正在将它们与pandas.testing.assert_frame_equal
进行比较,试图对数据进行一些自定义,以使其相等,希望得到一些帮助。
应删除第一列,并忽略标签名称
我想以最自然的方式做这件事,而不是只比较价值观
任何帮助都将不胜感激
我使用的数据帧:
解决方案:
谢谢你的回答
但是
df2.columns=df1.columns
失败并出现此错误:ValueError: Length mismatch: Expected axis has 3 elements, new values have 1 elements
打印这些列可以提供:
没有可能的改变,我如何比较它们
非常感谢你的帮助
您可以使用^{} 函数来比较数据帧。问题是列名必须匹配:
输出:
True
相关问题 更多 >
编程相关推荐