python - Getting AssertionError: (None, <10 * Seconds>) when comparing two "seemingly" identical dataframes
问题描述
Trying to create a mock data frame for an assertion. I have verified that the two data frames have the same dtypes and are both DateTimeIndex. However the Assertion fails with this:
Traceback (most recent call last):
tests/test_helpers.py line 143 in test_get_n_sec_metrics
assert_frame_equal(expected,actual)
lib/python3.8/site-packages/pandas/_testing.py line 1704 in assert_frame_equal
assert_series_equal(
lib/python3.8/site-packages/pandas/_testing.py line 1389 in assert_series_equal
assert lidx.freq == ridx.freq, (lidx.freq, ridx.freq) AssertionError: (None, <10 * Seconds>)
Which I interpret as the two df's having a mismatch in the frequency between the tested dataframe and my mock dataframe.
Here is my mock:
df_expected = pd.DataFrame({
'date':['2019-02-07 21:11:00','2019-02-07 21:11:10','2019-02-07 21:11:20'],
'letters':['a','b','c'],
'counts':[1,2,3],
})
df_expected['date']=pd.to_datetime(df_expected['date'])
df_expected.set_index('date', inplace=True)
df_expected.index.freq='10s'
Asking for a friend.
解决方案
好吧,没关系找到答案。这解决了它:
在行 df_expected.index.freq='10s' 切换10s
到10S
推荐阅读
- python - 字典python的空间复杂度
- python-3.x - 如何将日期作为熊猫数据框中的一列?
- git - Bitbucket 恢复到特定的提交,然后使用消息提交,然后推送到功能分支
- php - 如何将图像发布到此 Web 服务
- python - 使用熊猫转换嵌套数组/列表中的excel列
- sql - 使用 Microsoft Query 和 SQL 过程返回多行数据
- html - 如何在本地工作时在 HTML 文件中显示 SVG Sprite 图标?
- javascript - Discord.js 自定义表情符号错误看起来很简单,但我该如何解决?
- javascript - 将行号添加到预格式化文本
- django - React 和 Django 如何真正协同工作