- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在回答this stackoverflow question ,我在重新索引数据帧时使用填充方法时发现了一些有趣的行为。
这old bug report在 Pandas 中说 df.reindex(newIndex,method='ffill')
应该等同于 df.reindex(newIndex).ffill()
,但这不是我目睹的行为
这是一个说明行为的代码片段
df = pd.DataFrame({'values': 2}, index=pd.DatetimeIndex(['2016-06-02', '2016-05-04', '2016-06-03']))
newIndex = pd.DatetimeIndex(['2016-05-04', '2016-06-01', '2016-06-02', '2016-06-03', '2016-06-05'])
print(df.reindex(newIndex).ffill())
print(df.reindex(newIndex, method='ffill'))
第一个打印语句按预期工作。第二个提出了一个
ValueError: index must be monotonic increasing or decreasing
这是怎么回事?
编辑:请注意样本 df
有意有一个非单调索引。问题与 df.reindex(newIndex, method='ffil')
中的操作顺序有关.我的期望是错误报告说它应该工作 - 首先用新索引重新索引然后填充。
如您所见,newIndex.is_monotonic
是True
,填充在单独调用时有效,但在作为 reindex
的参数调用时失败。 .
最佳答案
reindex
的某些元素需要对传入索引进行排序。我推断当 method
被传递时,它无法对传入索引进行预排序,随后失败。我是基于这个有效的事实得出这个结论的:
print df.sort_index().reindex(newIndex.sort_values(), method='ffill')
关于python - Pandas 重建索引并填充缺失值 : "Index must be monotonic",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37982170/
计算机功能/过程/谓词必须满足哪些要求才能被视为“单调”? Let A be some thing , Let B be some thing , Let R be a monotonic relat
我正在本地 PC 上克隆一个 git 存储库。 在此过程中,该命令会输出大量以下错误消息: error: non-monotonic index .git/objects/pack/._pack-*.
我有一个我想从中提取的远程单调存储库,但我真的只需要最新版本(不,不需要历史记录。是的,我确定。而且我真的不想等待一个小时 -获得完整历史记录需要一半)。 有没有一种快速简便的方法可以做到这一点? 最
我需要在代码中处理超时情况,如果系统支持单调时钟,我想使用 clock_gettime(CLOCK_MONOTONIC)。 #ifdef CLOCK_MONOTONIC clock_getti
题目地址:https://leetcode.com/problems/monotone-increasing-digits/description/ 题目描述: Given a non-negat
我的 git 设置有一个我推送到的中央存储库。今天我决定使用 Git Extensions 查看中央存储库,它说该存储库没有提交(几乎就像从未创建过存储库一样)。调查这个问题,我尝试克隆 repo,它
我正在尝试配置从 mongo 副本集的主节点和两个辅助节点读取以提供更好的负载平衡。 3 个节点中的每一个都位于具有 IP 地址的不同机器上:ip1、ip2、ip3。 我的 GoLang 站点,即 m
题目地址:https://leetcode.com/problems/flip-string-to-monotone-increasing/description/ 题目描述 Astring of
这些是同一个时钟吗? time.monotonic() 和 asyncio.get_event_loop().time()。我的系统上似乎是这样,但除了这句话我找不到任何相关文档: Event loo
在回答this stackoverflow question ,我在重新索引数据帧时使用填充方法时发现了一些有趣的行为。 这old bug report在 Pandas 中说 df.reindex(n
我正在尝试使用 ffmpeg 添加两个视频,并且输出视频/音频不同步(并且快进)。目标是把 intro.mp4原文件前clip.flv 我的方法是 更改clip.flv的格式至clip.mp4 ffm
dfdata.Speed.rolling('60T', closed='right').sum() 我试图在这一列上应用滚动总和,并整理出整个数据,但仍然遇到相同的错误。谁能帮我解决一下??数据中索引
ser3 = Series(['美国','墨西哥','加拿大'],index = ['0','5','10']) 此处 ranger = range(15) 我在 iPython 中使用 Forwar
ser3 = Series(['美国','墨西哥','加拿大'],index = ['0','5','10']) 此处 ranger = range(15) 我在 iPython 中使用 Forwar
我有一个像这样的 Pandas 数据框: Balance Jan Feb Mar Apr 0 9.724135 0.389376 0.46
因此,在我将毫秒添加到日期/时间字段之前,我已经对数据进行了所有处理。 selected = selected['2017-02-20 16:10:05':'2017-02-20 16:20:06']
我有以下 DataFrame df: TIME DELAY 0 2016-01-01 06:30:00 0 1 2016-01-01 14
我对 libav 的经验几乎为零/FFMPEG .我编写了这段代码来捕获屏幕并将其写入文件,我正面临一些问题。我正在使用 AV_CODEC_ID_MPEG4起初编解码器,它工作得很好,但是非常快速的应
我需要连接来自不同来源的 mp4 文件,这意味着一些变量是我无法控制的,例如时基、纵横比和编码。因此,为了解决这个问题,我重新编码并尝试在连接文件之前对其进行标准化。不幸的是,尽管如此,我还是得到了
在处理遗留系统时,我需要使用仅接受 double 作为输入的函数来存储整数,我遇到了以下问题。我们给定一个二进制数,例如: 00111111 11000000 00000000 00000000 如果
我是一名优秀的程序员,十分优秀!