Pandas 从重采样中检索添加行的索引

2024-04-30

我有一个缺少行的数据框,我对其进行插值和重新采样。我想知道是否有办法在重新采样时获取添加到数据帧的行的索引?

这就是我创建/重新采样/插入数据帧的方式:

import numpy as np
import pandas as pd
from datetime import *

# Create df and drop a few rows
rng = pd.date_range('2000-01-01', periods=365, freq='D')
df = pd.DataFrame({'Val': np.random.randn(len(rng)) },index = rng)
df = df.drop([datetime(2000,1,5),datetime(2000,1,24)])

df = df.resample('D').interpolate(method='linear')

您可以通过获取附加索引元素不同之处 https://pandas.pydata.org/docs/reference/api/pandas.Index.difference.html新旧之间

In [16]: df_new = df.resample('D').interpolate(method='linear')

In [17]: df_new.index.difference(df.index)
Out[17]: DatetimeIndex(['2000-01-05', '2000-01-24'], dtype='datetime64[ns]', freq=None)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Pandas 从重采样中检索添加行的索引 的相关文章

随机推荐