【发布时间】:2013-05-24 08:32:51
【问题描述】:
我有一个整数 TimeSeries,我想使用 resample() 对其进行下采样。问题是我有一些缺失数据的时期被转换为NaN。由于 pandas 不支持Integer NA values,因此整数被转换为浮点数。
是否可以像使用reindex(fill_value=0) 一样使用fill_value 对缺失数据重新采样TimeSeries?我不希望我的整数转换成浮点数。
>>> dates = (datetime(2013, 1, 1), datetime(2013,1,2), datetime(2013,3,1))
>>> s = Series([1,2,4],index=dates)
>>> s
2013-01-01 1
2013-01-02 2
2013-03-01 4
dtype: int64
>>> s.resample('M', how='sum')
2013-01-31 3
2013-02-28 NaN
2013-03-31 4
Freq: M, dtype: float64
# Desired output (doesn't work)
>>> s.resample('M', how='sum', fill_value=0)
2013-01-31 3
2013-02-28 0
2013-03-31 4
Freq: M, dtype: int64
【问题讨论】:
-
奇怪的是你的第三个值是 4(索引为 2013-03-01 的那个)。
-
@waitingkuo 你是对的。修正了复制和粘贴的错字。
标签: python pandas time-series resampling