当我对某些数据进行重新采样时,我遇到了 pandas 丢弃第一行的问题。请看下面的例子。请注意,如果您将最后一个时间戳向前推进 1 秒,它会按预期工作。
我正在使用熊猫 0.10.1
import pandas as pd
from datetime import datetime
from StringIO import StringIO
f = StringIO('''\
time,value
2011-06-03 00:00:05,0
2011-06-03 00:01:05,1
2011-06-03 00:02:05,2
''')
series = pd.read_csv(f, parse_dates=True, index_col=0)['value']
print series
# time
# 2011-06-03 00:00:05 0
# 2011-06-03 00:01:05 1
# 2011-06-03 00:02:05 2
# Name: value
# Problem resampling: 1st sample is missing
print series.resample('s')
# time
# 2011-06-03 00:00:06 NaN
# 2011-06-03 00:00:07 NaN
# 2011-06-03 00:00:08 NaN
# 2011-06-03 00:00:09 NaN
# ...
# 2011-06-03 00:01:52 NaN
# 2011-06-03 00:02:03 NaN
# 2011-06-03 00:02:04 NaN
# 2011-06-03 00:02:05 2
# 2011-06-03 00:02:06 NaN
# Freq: S, Name: value, Length: 121