首页 > 解决方案 > 仅将一个数据帧的日期时间索引保留在另一个数据帧中

问题描述

我试图只保留一个数据帧的索引。两个索引都是 DateTimeindex。

但是,当我应用以下内容时:

df_noisy_test = df_noisy[df_noisy.index.isin(filtered.index)] # match index of test with filtered to remove imputed datapoints

我发现两个数据框的形状不同如下: (5061, 1)fordf_noisy_test(5056, 1)forfiltered

如何确保索引df_noisy_testfiltered仅使用/获取其索引的索引完全一致

(注意:两个数据帧都使用相同类型的 DateTimeIndex)

标签: pythonpandasdataframeindexingdatetimeindex

解决方案


推荐阅读