當前位置: 首頁>>代碼示例>>Python>>正文


Python pandas.Timestamp方法代碼示例

本文整理匯總了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) 
開發者ID:pywr,項目名稱:pywr,代碼行數:20,代碼來源:test_recorders.py

示例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
        ) 
開發者ID:refraction-ray,項目名稱:xalpha,代碼行數:25,代碼來源:info.py

示例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 
開發者ID:man-group,項目名稱:arctic,代碼行數:27,代碼來源:test_fixes.py

示例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') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_datetimes.py

示例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 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:25,代碼來源:test_datetimes.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:26,代碼來源:test_datetimelike.py

示例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')) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_datetimelike.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:test_base.py

示例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) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:test_base.py

示例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') 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:24,代碼來源:test_construction.py

示例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 
開發者ID:pywr,項目名稱:pywr,代碼行數:8,代碼來源:timestepper.py

示例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 
開發者ID:pywr,項目名稱:pywr,代碼行數:8,代碼來源:timestepper.py

示例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 
開發者ID:pywr,項目名稱:pywr,代碼行數:42,代碼來源:figures.py

示例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 
開發者ID:pywr,項目名稱:pywr,代碼行數:7,代碼來源:test_agg_constraints.py

示例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) 
開發者ID:pywr,項目名稱:pywr,代碼行數:31,代碼來源:test_agg_constraints.py


注:本文中的pandas.Timestamp方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。