如果我使用以下方法来构造 a pandas.DataFrame,我会得到一个(我认为)很特殊的输出:
import pandas, numpy
df = pandas.DataFrame(
    numpy.random.rand(100,2), index = numpy.arange(100), columns = ['s1','s2'])
smoothed = pandas.DataFrame(
    pandas.ewma(df, span = 21), index = df.index, columns = ['smooth1','smooth2'])
当我查看平滑值时,我得到:
>>> smoothed.tail()
smooth1  smooth2
95      NaN      NaN
96      NaN      NaN
97      NaN      NaN
98      NaN      NaN
99      NaN      NaN
这似乎是以下碎片调用的聚合,它们会产生不同的结果:
smoothed2 = pandas.DataFrame(pandas.ewma(df, span = 21))
smoothed2.index = df.index
smoothed2.columns = ['smooth1','smooth2']
再次使用DataFrame.tail()我得到的调用:
>>> smoothed2.tail()
smooth1   smooth2
95  0.496021  0.501153 
96  0.506118  0.507541
97  0.516655  0.544621
98  0.520212  0.543751
99  0.518170  0.572429
任何人都可以提供为什么这些 DataFrame 构造方法应该不同的理由吗?