本文整理汇总了Python中pandas.Timestamp方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.Timestamp方法的具体用法?Python pandas.Timestamp怎么用?Python pandas.Timestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pandas
的用法示例。
在下文中一共展示了pandas.Timestamp方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_seasonal_fdc_recorder
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_seasonal_fdc_recorder(self):
"""
Test the FlowDurationCurveRecorder
"""
model = load_model("timeseries4.json")
df = pandas.read_csv(os.path.join(os.path.dirname(__file__), 'models', 'timeseries3.csv'),
parse_dates=True, dayfirst=True, index_col=0)
percentiles = np.linspace(20., 100., 5)
summer_flows = df.loc[pandas.Timestamp("2014-06-01"):pandas.Timestamp("2014-08-31"), :]
summer_fdc = np.percentile(summer_flows, percentiles, axis=0)
model.run()
rec = model.recorders["seasonal_fdc"]
assert_allclose(rec.fdc, summer_fdc)
示例2: _save_sql
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def _save_sql(self, path):
"""
save the information and pricetable into sql, not recommend to use manually,
just set the save label to be true when init the object
:param path: engine object from sqlalchemy
"""
s = json.dumps(
{
"feeinfo": self.feeinfo,
"name": self.name,
"rate": self.rate,
"segment": self.segment,
}
)
df = pd.DataFrame(
[[pd.Timestamp("1990-01-01"), 0, s, 0]],
columns=["date", "netvalue", "comment", "totvalue"],
)
df = df.append(self.price, ignore_index=True, sort=True)
df.sort_index(axis=1).to_sql(
"xa" + self.code, con=path, if_exists="replace", index=False
)
示例3: test_iterator
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_iterator(chunkstore_lib):
"""
Fixes issue #431 - iterator methods were not taking into account
the fact that symbols can have multiple segments
"""
def generate_data(date):
"""
Generates a dataframe that is larger than one segment
a segment in chunkstore
"""
df = pd.DataFrame(np.random.randn(200000, 12),
columns=['beta', 'btop', 'earnyild', 'growth', 'industry', 'leverage',
'liquidty', 'momentum', 'resvol', 'sid', 'size', 'sizenl'])
df['date'] = date
return df
date = pd.Timestamp('2000-01-01')
df = generate_data(date)
chunkstore_lib.write('test', df, chunk_size='A')
ret = chunkstore_lib.get_chunk_ranges('test')
assert(len(list(ret)) == 1)
# Issue 722
示例4: test_fillna_preserves_tz
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_fillna_preserves_tz(self, method):
dti = pd.date_range('2000-01-01', periods=5, freq='D', tz='US/Central')
arr = DatetimeArray(dti, copy=True)
arr[2] = pd.NaT
fill_val = dti[1] if method == 'pad' else dti[3]
expected = DatetimeArray._from_sequence(
[dti[0], dti[1], fill_val, dti[3], dti[4]],
freq=None, tz='US/Central'
)
result = arr.fillna(method=method)
tm.assert_extension_array_equal(result, expected)
# assert that arr and dti were not modified in-place
assert arr[2] is pd.NaT
assert dti[2] == pd.Timestamp('2000-01-03', tz='US/Central')
示例5: test_min_max
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_min_max(self, tz):
arr = DatetimeArray._from_sequence([
'2000-01-03',
'2000-01-03',
'NaT',
'2000-01-02',
'2000-01-05',
'2000-01-04',
], tz=tz)
result = arr.min()
expected = pd.Timestamp('2000-01-02', tz=tz)
assert result == expected
result = arr.max()
expected = pd.Timestamp('2000-01-05', tz=tz)
assert result == expected
result = arr.min(skipna=False)
assert result is pd.NaT
result = arr.max(skipna=False)
assert result is pd.NaT
示例6: test_take_fill
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_take_fill(self):
data = np.arange(10, dtype='i8') * 24 * 3600 * 10**9
idx = self.index_cls._simple_new(data, freq='D')
arr = self.array_cls(idx)
result = arr.take([-1, 1], allow_fill=True, fill_value=None)
assert result[0] is pd.NaT
result = arr.take([-1, 1], allow_fill=True, fill_value=np.nan)
assert result[0] is pd.NaT
result = arr.take([-1, 1], allow_fill=True, fill_value=pd.NaT)
assert result[0] is pd.NaT
with pytest.raises(ValueError):
arr.take([0, 1], allow_fill=True, fill_value=2)
with pytest.raises(ValueError):
arr.take([0, 1], allow_fill=True, fill_value=2.0)
with pytest.raises(ValueError):
arr.take([0, 1], allow_fill=True,
fill_value=pd.Timestamp.now().time)
示例7: test_take_fill_valid
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_take_fill_valid(self, timedelta_index):
tdi = timedelta_index
arr = TimedeltaArray(tdi)
td1 = pd.Timedelta(days=1)
result = arr.take([-1, 1], allow_fill=True, fill_value=td1)
assert result[0] == td1
now = pd.Timestamp.now()
with pytest.raises(ValueError):
# fill_value Timestamp invalid
arr.take([0, 1], allow_fill=True, fill_value=now)
with pytest.raises(ValueError):
# fill_value Period invalid
arr.take([0, 1], allow_fill=True, fill_value=now.to_period('D'))
示例8: test_union_sort_other_incomparable
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_union_sort_other_incomparable(self):
# https://github.com/pandas-dev/pandas/issues/24959
idx = pd.Index([1, pd.Timestamp('2000')])
# default (sort=None)
with tm.assert_produces_warning(RuntimeWarning):
result = idx.union(idx[:1])
tm.assert_index_equal(result, idx)
# sort=None
with tm.assert_produces_warning(RuntimeWarning):
result = idx.union(idx[:1], sort=None)
tm.assert_index_equal(result, idx)
# sort=False
result = idx.union(idx[:1], sort=False)
tm.assert_index_equal(result, idx)
示例9: test_difference_incomparable
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_difference_incomparable(self, opname):
a = pd.Index([3, pd.Timestamp('2000'), 1])
b = pd.Index([2, pd.Timestamp('1999'), 1])
op = operator.methodcaller(opname, b)
# sort=None, the default
result = op(a)
expected = pd.Index([3, pd.Timestamp('2000'), 2, pd.Timestamp('1999')])
if opname == 'difference':
expected = expected[:2]
tm.assert_index_equal(result, expected)
# sort=False
op = operator.methodcaller(opname, b, sort=False)
result = op(a)
tm.assert_index_equal(result, expected)
示例10: test_dti_with_timedelta64_data_deprecation
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_dti_with_timedelta64_data_deprecation(self):
# GH#23675
data = np.array([0], dtype='m8[ns]')
with tm.assert_produces_warning(FutureWarning):
result = DatetimeIndex(data)
assert result[0] == Timestamp('1970-01-01')
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = to_datetime(data)
assert result[0] == Timestamp('1970-01-01')
with tm.assert_produces_warning(FutureWarning):
result = DatetimeIndex(pd.TimedeltaIndex(data))
assert result[0] == Timestamp('1970-01-01')
with tm.assert_produces_warning(FutureWarning, check_stacklevel=False):
result = to_datetime(pd.TimedeltaIndex(data))
assert result[0] == Timestamp('1970-01-01')
示例11: start
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def start(self, value):
if isinstance(value, pandas.Timestamp):
self._start = value
else:
self._start = pandas.to_datetime(value)
self._dirty = True
示例12: end
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def end(self, value):
if isinstance(value, pandas.Timestamp):
self._end = value
else:
self._end = pandas.to_datetime(value)
self._dirty = True
示例13: align_series
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def align_series(A, B, names=None, start=None, end=None):
"""Align two series for plotting / comparison
Parameters
----------
A : `pandas.Series`
B : `pandas.Series`
names : list of strings
start : `pandas.Timestamp` or timestamp string
end : `pandas.Timestamp` or timestamp string
Example
-------
>>> A, B = align_series(A, B, ["Pywr", "Aquator"], start="1920-01-01", end="1929-12-31")
>>> plot_standard1(A, B)
"""
# join series B to series A
# TODO: better handling of heterogeneous frequencies
df = pandas.concat([A, B], join="inner", axis=1)
# apply names
if names is not None:
df.columns = names
else:
names = list(df.columns)
# clip start and end to user-specified dates
idx = [df.index[0], df.index[-1]]
if start is not None:
idx[0] = pandas.Timestamp(start)
if end is not None:
idx[1] = pandas.Timestamp(end)
if start or end:
df = df.loc[idx[0]:idx[-1],:]
A = df[names[0]]
B = df[names[1]]
return A, B
示例14: model
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def model():
model = Model()
model.timestepper.start = Timestamp("2016-01-01")
model.timestepper.end = Timestamp("2016-01-02")
return model
示例15: test_aggregated_node_two_factors_time_varying
# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import Timestamp [as 别名]
def test_aggregated_node_two_factors_time_varying(model):
"""Nodes constrained by a time-varying ratio between flows (2 nodes)"""
model.timestepper.end = Timestamp("2016-01-03")
A = Input(model, "A")
B = Input(model, "B", max_flow=40.0)
Z = Output(model, "Z", max_flow=100, cost=-10)
agg = AggregatedNode(model, "agg", [A, B])
agg.factors = [0.5, 0.5]
assert_allclose(agg.factors, [0.5, 0.5])
A.connect(Z)
B.connect(Z)
model.setup()
model.step()
assert_allclose(agg.flow, 80.0)
assert_allclose(A.flow, 40.0)
assert_allclose(B.flow, 40.0)
agg.factors = [1.0, 2.0]
model.step()
assert_allclose(agg.flow, 60.0)
assert_allclose(A.flow, 20.0)
assert_allclose(B.flow, 40.0)