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


Python datetime.month方法代碼示例

本文整理匯總了Python中datetime.datetime.month方法的典型用法代碼示例。如果您正苦於以下問題:Python datetime.month方法的具體用法?Python datetime.month怎麽用?Python datetime.month使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在datetime.datetime的用法示例。


在下文中一共展示了datetime.month方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: extract_month

# 需要導入模塊: from datetime import datetime [as 別名]
# 或者: from datetime.datetime import month [as 別名]
def extract_month(utc_timestamp):
    """
        Extracts month from utc timestamp string.
    """

    datetime = parser.parse(utc_timestamp)
    return '{0}-{1}'.format(datetime.year, datetime.month) 
開發者ID:Djacket,項目名稱:djacket,代碼行數:9,代碼來源:statistics.py

示例2: extract_day

# 需要導入模塊: from datetime import datetime [as 別名]
# 或者: from datetime.datetime import month [as 別名]
def extract_day(utc_timestamp):
    """
        Extracts day from utc timestamp string.
    """

    datetime = parser.parse(utc_timestamp)
    return '{0}-{1}-{2}'.format(datetime.year, datetime.month, datetime.day) 
開發者ID:Djacket,項目名稱:djacket,代碼行數:9,代碼來源:statistics.py

示例3: _for_commits_monthly

# 需要導入模塊: from datetime import datetime [as 別名]
# 或者: from datetime.datetime import month [as 別名]
def _for_commits_monthly(self, commits):
        """
            Returns number of commits per month for the given commits.
        """

        dates = [get_month(extract_month(commit.get_committer_date())) for commit in commits
                        if get_year(commit.get_committer_date()) == self.current_year]
        return {mn: dates.count(mn) if mn in dates else 0 for mn in range(1, 13)} 
開發者ID:Djacket,項目名稱:djacket,代碼行數:10,代碼來源:statistics.py

示例4: test_sort_datetimelike

# 需要導入模塊: from datetime import datetime [as 別名]
# 或者: from datetime.datetime import month [as 別名]
def test_sort_datetimelike():
    # GH10505

    # use same data as test_groupby_sort_categorical, which category is
    # corresponding to datetime.month
    df = DataFrame({'dt': [datetime(2011, 7, 1), datetime(2011, 7, 1),
                           datetime(2011, 2, 1), datetime(2011, 5, 1),
                           datetime(2011, 2, 1), datetime(2011, 1, 1),
                           datetime(2011, 5, 1)],
                    'foo': [10, 8, 5, 6, 4, 1, 7],
                    'bar': [10, 20, 30, 40, 50, 60, 70]},
                   columns=['dt', 'foo', 'bar'])

    # ordered=True
    df['dt'] = Categorical(df['dt'], ordered=True)
    index = [datetime(2011, 1, 1), datetime(2011, 2, 1),
             datetime(2011, 5, 1), datetime(2011, 7, 1)]
    result_sort = DataFrame(
        [[1, 60], [5, 30], [6, 40], [10, 10]], columns=['foo', 'bar'])
    result_sort.index = CategoricalIndex(index, name='dt', ordered=True)

    index = [datetime(2011, 7, 1), datetime(2011, 2, 1),
             datetime(2011, 5, 1), datetime(2011, 1, 1)]
    result_nosort = DataFrame([[10, 10], [5, 30], [6, 40], [1, 60]],
                              columns=['foo', 'bar'])
    result_nosort.index = CategoricalIndex(index, categories=index,
                                           name='dt', ordered=True)

    col = 'dt'
    assert_frame_equal(
        result_sort, df.groupby(col, sort=True, observed=False).first())

    # when categories is ordered, group is ordered by category's order
    assert_frame_equal(
        result_sort, df.groupby(col, sort=False, observed=False).first())

    # ordered = False
    df['dt'] = Categorical(df['dt'], ordered=False)
    index = [datetime(2011, 1, 1), datetime(2011, 2, 1),
             datetime(2011, 5, 1), datetime(2011, 7, 1)]
    result_sort = DataFrame(
        [[1, 60], [5, 30], [6, 40], [10, 10]], columns=['foo', 'bar'])
    result_sort.index = CategoricalIndex(index, name='dt')

    index = [datetime(2011, 7, 1), datetime(2011, 2, 1),
             datetime(2011, 5, 1), datetime(2011, 1, 1)]
    result_nosort = DataFrame([[10, 10], [5, 30], [6, 40], [1, 60]],
                              columns=['foo', 'bar'])
    result_nosort.index = CategoricalIndex(index, categories=index,
                                           name='dt')

    col = 'dt'
    assert_frame_equal(
        result_sort, df.groupby(col, sort=True, observed=False).first())
    assert_frame_equal(
        result_nosort, df.groupby(col, sort=False, observed=False).first()) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:58,代碼來源:test_categorical.py

示例5: test_groupby_sort_categorical_datetimelike

# 需要導入模塊: from datetime import datetime [as 別名]
# 或者: from datetime.datetime import month [as 別名]
def test_groupby_sort_categorical_datetimelike(self):
        # GH10505

        # use same data as test_groupby_sort_categorical, which category is
        # corresponding to datetime.month
        df = DataFrame({'dt': [datetime(2011, 7, 1), datetime(2011, 7, 1),
                               datetime(2011, 2, 1), datetime(2011, 5, 1),
                               datetime(2011, 2, 1), datetime(2011, 1, 1),
                               datetime(2011, 5, 1)],
                        'foo': [10, 8, 5, 6, 4, 1, 7],
                        'bar': [10, 20, 30, 40, 50, 60, 70]},
                       columns=['dt', 'foo', 'bar'])

        # ordered=True
        df['dt'] = Categorical(df['dt'], ordered=True)
        index = [datetime(2011, 1, 1), datetime(2011, 2, 1),
                 datetime(2011, 5, 1), datetime(2011, 7, 1)]
        result_sort = DataFrame(
            [[1, 60], [5, 30], [6, 40], [10, 10]], columns=['foo', 'bar'])
        result_sort.index = CategoricalIndex(index, name='dt', ordered=True)

        index = [datetime(2011, 7, 1), datetime(2011, 2, 1),
                 datetime(2011, 5, 1), datetime(2011, 1, 1)]
        result_nosort = DataFrame([[10, 10], [5, 30], [6, 40], [1, 60]],
                                  columns=['foo', 'bar'])
        result_nosort.index = CategoricalIndex(index, categories=index,
                                               name='dt', ordered=True)

        col = 'dt'
        assert_frame_equal(result_sort, df.groupby(col, sort=True).first())
        # when categories is ordered, group is ordered by category's order
        assert_frame_equal(result_sort, df.groupby(col, sort=False).first())

        # ordered = False
        df['dt'] = Categorical(df['dt'], ordered=False)
        index = [datetime(2011, 1, 1), datetime(2011, 2, 1),
                 datetime(2011, 5, 1), datetime(2011, 7, 1)]
        result_sort = DataFrame(
            [[1, 60], [5, 30], [6, 40], [10, 10]], columns=['foo', 'bar'])
        result_sort.index = CategoricalIndex(index, name='dt')

        index = [datetime(2011, 7, 1), datetime(2011, 2, 1),
                 datetime(2011, 5, 1), datetime(2011, 1, 1)]
        result_nosort = DataFrame([[10, 10], [5, 30], [6, 40], [1, 60]],
                                  columns=['foo', 'bar'])
        result_nosort.index = CategoricalIndex(index, categories=index,
                                               name='dt')

        col = 'dt'
        assert_frame_equal(result_sort, df.groupby(col, sort=True).first())
        assert_frame_equal(result_nosort, df.groupby(col, sort=False).first()) 
開發者ID:securityclippy,項目名稱:elasticintel,代碼行數:53,代碼來源:test_categorical.py


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