本文整理汇总了Python中pandas.TimeSeries类的典型用法代码示例。如果您正苦于以下问题:Python TimeSeries类的具体用法?Python TimeSeries怎么用?Python TimeSeries使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeSeries类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resample_5minute
def test_resample_5minute(self):
rng = period_range('1/1/2000', '1/5/2000', freq='T')
ts = TimeSeries(np.random.randn(len(rng)), index=rng)
result = ts.resample('5min')
expected = ts.to_timestamp().resample('5min')
assert_series_equal(result, expected)
示例2: save2csv
def save2csv(r, csvpath=None, fileNamePrefix=''):
"""
Parse and save to csv
"""
# Create Dataframe
try:
d = {}
for tup in r.json():
d[dt.fromtimestamp(tup[0])] = tup[1]
#pdb.set_trace()
Ts = TimeSeries(data=d)
# this line gives an error. Should be checked, but for now I keep the nan's
# Ts = Ts[Ts != 'nan']
except:
print "-------> Problem with Flukso data parsing <-------"
raise
# save to file
if csvpath is None:
csvpath = os.getcwd()
s = strftime("%Y-%m-%d_%H-%M-%S",Ts.index[0].timetuple())
e = strftime("%Y-%m-%d_%H-%M-%S",Ts.index[-1].timetuple())
Ts.to_csv(os.path.join(csvpath, fileNamePrefix + '_FROM_' + s +
'_TO_' + e + '.csv'))
示例3: test_pad_nan
def test_pad_nan(self):
x = TimeSeries([np.nan, 1., np.nan, 3., np.nan],
['z', 'a', 'b', 'c', 'd'], dtype=float)
x = x.fillna(method='pad')
expected = TimeSeries([np.nan, 1.0, 1.0, 3.0, 3.0],
['z', 'a', 'b', 'c', 'd'], dtype=float)
assert_series_equal(x[1:], expected[1:])
self.assert_(np.isnan(x[0]), np.isnan(expected[0]))
示例4: test_median
def test_median(self):
self.assertAlmostEqual(np.median(self.ts), self.ts.median())
ts = self.ts.copy()
ts[::2] = np.NaN
self.assertAlmostEqual(np.median(ts.valid()), ts.median())
# test with integers, test failure
int_ts = TimeSeries(np.ones(10, dtype=int), index=range(10))
self.assertAlmostEqual(np.median(int_ts), int_ts.median())
示例5: __init__
def __init__(self, data, dtime,**kwargs):
"""
Time series w/ specific IO methods
"""
self.__dict__.update(kwargs)
TimeSeries.__init__(self, data, index=dtime)
#super(ObsTimeSeries,self).__init__(data,index=dtime)
# Time coordinates
self.nt = self.index.shape
self.tsec = othertime.SecondsSince(self.index,\
basetime = pd.datetime(self.baseyear,1,1))
示例6: test_resample_fill_missing
def test_resample_fill_missing(self):
rng = PeriodIndex([2000, 2005, 2007, 2009], freq='A')
s = TimeSeries(np.random.randn(4), index=rng)
stamps = s.to_timestamp()
filled = s.resample('A')
expected = stamps.resample('A').to_period('A')
assert_series_equal(filled, expected)
filled = s.resample('A', fill_method='ffill')
expected = stamps.resample('A', fill_method='ffill').to_period('A')
assert_series_equal(filled, expected)
示例7: _split
def _split(self, frame):
if self.share_afterward == 1:
return
splits = [self.share_afterward, 1.0]
adj_day = self.ex_date - datetime.timedelta(days=1)
indexes = []
indexes.append(adj_day)
indexes.append(datetime.date.today())
splits = TimeSeries(splits, index=indexes)
ri_splits = splits.reindex(frame.index, method='backfill')
frame['adjclose'] = frame['adjclose'] / ri_splits
示例8: _divide
def _divide(self, frame):
if self.cash_afterward == 0:
return
cashes = [self.cash_afterward, 0.0]
adj_day = self.ex_date - datetime.timedelta(days=1)
indexes = []
indexes.append(adj_day)
indexes.append(datetime.date.today())
cashes = TimeSeries(cashes, index=indexes)
ri_cashes = cashes.reindex(frame.index, method='backfill')
frame['adjclose'] = frame['adjclose'] - ri_cashes
示例9: _divide
def _divide(self, frame):
"""divided close price to adjclose column
WARNING
=======
frame should be chronological ordered otherwise wrong backfill.
"""
if self.cash_afterward == 0:
return
cashes = [self.cash_afterward, 0.0]
adj_day = self.ex_date - datetime.timedelta(days=1)
indexes = []
indexes.append(self.d2t(adj_day))
indexes.append(self.d2t(datetime.date.today()))
cashes = TimeSeries(cashes, index=indexes)
ri_cashes = cashes.reindex(frame.index, method='backfill')
frame['adjclose'] = frame['adjclose'] - ri_cashes
示例10: test_median
def test_median(self):
self._check_stat_op('median', np.median)
# test with integers, test failure
int_ts = TimeSeries(np.ones(10, dtype=int), index=range(10))
self.assertAlmostEqual(np.median(int_ts), int_ts.median())