当前位置: 首页>>代码示例>>Python>>正文


Python pandas.datetime方法代码示例

本文整理汇总了Python中pandas.datetime方法的典型用法代码示例。如果您正苦于以下问题:Python pandas.datetime方法的具体用法?Python pandas.datetime怎么用?Python pandas.datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas的用法示例。


在下文中一共展示了pandas.datetime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _filter_datetime_input

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def _filter_datetime_input(self, date):
        """
        Returns datetime that only includes year, month, and day.

        Parameters
        ----------
        date : datetime (array_like or single input)

        Returns
        -------
        datetime (or list of datetimes)
            Only includes year, month, and day from original input

        """

        if date is None:
            return date
        else:
            if hasattr(date, '__iter__'):
                return [pds.datetime(da.year, da.month, da.day) for da in date]
            else:
                return pds.datetime(date.year, date.month, date.day) 
开发者ID:pysat,项目名称:pysat,代码行数:24,代码来源:_instrument.py

示例2: getyrdoy

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def getyrdoy(date):
    """Return a tuple of year, day of year for a supplied datetime object.

    Parameters
    ----------
    date : datetime.datetime
        Datetime object

    Returns
    -------
    year : int
        Integer year
    doy : int
        Integer day of year

    """

    try:
        doy = date.toordinal() - datetime(date.year, 1, 1).toordinal() + 1
    except AttributeError:
        raise AttributeError("Must supply a pandas datetime object or " +
                             "equivalent")
    else:
        return date.year, doy 
开发者ID:pysat,项目名称:pysat,代码行数:26,代码来源:time.py

示例3: create_date_range

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def create_date_range(start, stop, freq='D'):
    """
    Return array of datetime objects using input frequency from start to stop

    Supports single datetime object or list, tuple, ndarray of start and
    stop dates.

    freq codes correspond to pandas date_range codes, D daily, M monthly,
    S secondly

    """

    if hasattr(start, '__iter__'):
        # missing check for datetime
        season = pds.date_range(start[0], stop[0], freq=freq)
        for (sta, stp) in zip(start[1:], stop[1:]):
            season = season.append(pds.date_range(sta, stp, freq=freq))
    else:
        season = pds.date_range(start, stop, freq=freq)
    return season 
开发者ID:pysat,项目名称:pysat,代码行数:22,代码来源:time.py

示例4: get_new

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def get_new(self):
        """List new files since last recorded file state.

        pysat stores filenames in the user_home/.pysat directory. Returns
        a list of all new fileanmes since the last known change to files.
        Filenames are stored if there is a change and either update_files
        is True at instrument object level or files.refresh() is called.

        Returns
        -------
        pandas.Series
            files are indexed by datetime

        """

        # refresh files
        self.refresh()
        # current files
        new_info = self._load()
        # previous set of files
        old_info = self._load(prev_version=True)
        new_files = new_info[-new_info.isin(old_info)]
        return new_files 
开发者ID:pysat,项目名称:pysat,代码行数:25,代码来源:_files.py

示例5: test_deprecated_season_date_range

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def test_deprecated_season_date_range():
    """Tests that deprecation of season_date_range is working"""

    import warnings

    start = pds.datetime(2012, 2, 28)
    stop = pds.datetime(2012, 3, 1)
    warnings.simplefilter("always")
    with warnings.catch_warnings(record=True) as war1:
        season1 = pytime.create_date_range(start, stop, freq='D')
    with warnings.catch_warnings(record=True) as war2:
        season2 = pytime.season_date_range(start, stop, freq='D')

    assert len(season1) == len(season2)
    assert (season1 == season2).all()
    assert len(war1) == 0
    assert len(war2) == 1
    assert war2[0].category == DeprecationWarning 
开发者ID:pysat,项目名称:pysat,代码行数:20,代码来源:test_utils_time.py

示例6: test_prev_filename_load_default

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def test_prev_filename_load_default(self):
        """Test prev day is loaded when invoking .prev."""
        self.testInst.load(fname='2009-01-04.nofile')
        # print(self.testInst.date)
        self.testInst.prev()
        test_date = self.testInst.index[0]
        test_date = pysat.datetime(test_date.year, test_date.month,
                                   test_date.day)
        assert (test_date == pds.datetime(2009, 1, 3))
        assert (test_date == self.testInst.date)

    # --------------------------------------------------------------------------
    #
    # Test date helpers
    #
    # -------------------------------------------------------------------------- 
开发者ID:pysat,项目名称:pysat,代码行数:18,代码来源:test_instrument.py

示例7: test_iterate_over_bounds_set_by_date_season_extra_time

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def test_iterate_over_bounds_set_by_date_season_extra_time(self):
        start = [pysat.datetime(2009, 1, 1, 1, 10),
                 pysat.datetime(2009, 2, 1, 1, 10)]
        stop = [pysat.datetime(2009, 1, 15, 1, 10),
                pysat.datetime(2009, 2, 15, 1, 10)]
        self.testInst.bounds = (start, stop)
        # filter
        start = self.testInst._filter_datetime_input(start)
        stop = self.testInst._filter_datetime_input(stop)
        # iterate
        dates = []
        for inst in self.testInst:
            dates.append(inst.date)
        out = pds.date_range(start[0], stop[0]).tolist()
        out.extend(pds.date_range(start[1], stop[1]).tolist())
        assert np.all(dates == out) 
开发者ID:pysat,项目名称:pysat,代码行数:18,代码来源:test_instrument.py

示例8: test_iterate_over_bounds_set_by_fname_via_next

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def test_iterate_over_bounds_set_by_fname_via_next(self):
        start = '2009-01-01.nofile'
        stop = '2009-01-15.nofile'
        start_d = pysat.datetime(2009, 1, 1)
        stop_d = pysat.datetime(2009, 1, 15)
        self.testInst.bounds = (start, stop)
        dates = []
        loop_next = True
        while loop_next:
            try:
                self.testInst.next()
                dates.append(self.testInst.date)
            except StopIteration:
                loop_next = False
        out = pds.date_range(start_d, stop_d).tolist()
        assert np.all(dates == out) 
开发者ID:pysat,项目名称:pysat,代码行数:18,代码来源:test_instrument.py

示例9: test_iterate_over_bounds_set_by_fname_via_prev

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def test_iterate_over_bounds_set_by_fname_via_prev(self):
        start = '2009-01-01.nofile'
        stop = '2009-01-15.nofile'
        start_d = pysat.datetime(2009, 1, 1)
        stop_d = pysat.datetime(2009, 1, 15)
        self.testInst.bounds = (start, stop)
        dates = []
        loop = True
        while loop:
            try:
                self.testInst.prev()
                dates.append(self.testInst.date)
            except StopIteration:
                loop = False
        out = pds.date_range(start_d, stop_d).tolist()
        assert np.all(dates == out[::-1]) 
开发者ID:pysat,项目名称:pysat,代码行数:18,代码来源:test_instrument.py

示例10: filter_data

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def filter_data(inst):
    """Remove data from instrument, simulating gaps"""

    times = [[pysat.datetime(2009, 1, 1, 10),
              pysat.datetime(2009, 1, 1, 12)],
             [pysat.datetime(2009, 1, 1, 4),
              pysat.datetime(2009, 1, 2, 5, 37)],
             [pysat.datetime(2009, 1, 1, 1, 37),
              pysat.datetime(2009, 1, 1, 3, 14)],
             [pysat.datetime(2009, 1, 1, 15),
              pysat.datetime(2009, 1, 1, 16)],
             [pysat.datetime(2009, 1, 1, 22),
              pysat.datetime(2009, 1, 2, 2)],
             [pysat.datetime(2009, 1, 13),
              pysat.datetime(2009, 1, 15)],
             [pysat.datetime(2009, 1, 20, 1),
              pysat.datetime(2009, 1, 25, 23)],
             [pysat.datetime(2009, 1, 25, 23, 30),
              pysat.datetime(2009, 1, 26, 3)]
             ]
    for time in times:
        idx, = np.where((inst.index > time[1]) | (inst.index < time[0]))
        inst.data = inst[idx] 
开发者ID:pysat,项目名称:pysat,代码行数:25,代码来源:test_orbits.py

示例11: setup

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def setup(self):
        """Runs before every method to create a clean testing setup."""
        info = {'index': 'mlt'}
        self.testInst = pysat.Instrument('pysat', 'testing',
                                         clean_level='clean',
                                         orbit_info=info)
        times = [[pysat.datetime(2008, 12, 31, 4),
                  pysat.datetime(2008, 12, 31, 5, 37)],
                 [pysat.datetime(2009, 1, 1),
                  pysat.datetime(2009, 1, 1, 1, 37)]
                 ]
        for seconds in np.arange(38):
            day = pysat.datetime(2009, 1, 2) + \
                pds.DateOffset(days=int(seconds))
            times.append([day, day +
                          pds.DateOffset(hours=1, minutes=37,
                                         seconds=int(seconds)) -
                          pds.DateOffset(seconds=20)])

        self.testInst.custom.add(filter_data2, 'modify', times=times) 
开发者ID:pysat,项目名称:pysat,代码行数:22,代码来源:test_orbits.py

示例12: test_setitem_mixed_datetime

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def test_setitem_mixed_datetime(self):
        # GH 9336
        expected = DataFrame({'a': [0, 0, 0, 0, 13, 14],
                              'b': [pd.datetime(2012, 1, 1),
                                    1,
                                    'x',
                                    'y',
                                    pd.datetime(2013, 1, 1),
                                    pd.datetime(2014, 1, 1)]})
        df = pd.DataFrame(0, columns=list('ab'), index=range(6))
        df['b'] = pd.NaT
        df.loc[0, 'b'] = pd.datetime(2012, 1, 1)
        df.loc[1, 'b'] = 1
        df.loc[[2, 3], 'b'] = 'x', 'y'
        A = np.array([[13, np.datetime64('2013-01-01T00:00:00')],
                      [14, np.datetime64('2014-01-01T00:00:00')]])
        df.loc[[4, 5], ['a', 'b']] = A
        assert_frame_equal(df, expected) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:test_indexing.py

示例13: setup_method

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def setup_method(self, datapath):
        self.dirpath = datapath("io", "sas", "data")
        self.data = []
        self.test_ix = [list(range(1, 16)), [16]]
        for j in 1, 2:
            fname = os.path.join(
                self.dirpath, "test_sas7bdat_{j}.csv".format(j=j))
            df = pd.read_csv(fname)
            epoch = pd.datetime(1960, 1, 1)
            t1 = pd.to_timedelta(df["Column4"], unit='d')
            df["Column4"] = epoch + t1
            t2 = pd.to_timedelta(df["Column12"], unit='d')
            df["Column12"] = epoch + t2
            for k in range(df.shape[1]):
                col = df.iloc[:, k]
                if col.dtype == np.int64:
                    df.iloc[:, k] = df.iloc[:, k].astype(np.float64)
                elif col.dtype == np.dtype('O'):
                    if PY2:
                        f = lambda x: (x.decode('utf-8') if
                                       isinstance(x, str) else x)
                        df.iloc[:, k] = df.iloc[:, k].apply(f)
            self.data.append(df) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:25,代码来源:test_sas7bdat.py

示例14: today

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def today(self):
        """Returns today's date, with no hour, minute, second, etc.

        Parameters
        ----------
        None

        Returns
        -------
        datetime
            Today's date

        """

        return self._filter_datetime_input(pds.datetime.today()) 
开发者ID:pysat,项目名称:pysat,代码行数:17,代码来源:_instrument.py

示例15: tomorrow

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import datetime [as 别名]
def tomorrow(self):
        """Returns tomorrow's date, with no hour, minute, second, etc.

        Parameters
        ----------
        None

        Returns
        -------
        datetime
            Tomorrow's date

        """

        return self.today() + pds.DateOffset(days=1) 
开发者ID:pysat,项目名称:pysat,代码行数:17,代码来源:_instrument.py


注:本文中的pandas.datetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。