Python中的下采样变量和插值NaN

2024-09-30 14:35:51 发布

您现在位置:Python中文网/ 问答频道 /正文

问题是

import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()

closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)

对上述步骤中过滤的数据进行向下采样,并执行插值以正向填充前两个“NaN”值。 将下采样数据的前10个样本返回变量“downsample”

我试过下面的方法

downsample1 = closeTS.resample('D', fill_method='ffill')
downsample = downsample1.interpolate(method='linear',limit=None,limit_direction='forward')
print(downsample.head(10))

然而,上面的代码似乎不起作用


Tags: 数据importdataframepandasreaddateindexas