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


Python pandas.groupby方法代码示例

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


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

示例1: _plotWeekdayStats

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import groupby [as 别名]
def _plotWeekdayStats(stats, columns, groupBy=True):
    dataToPlot = stats.copy()
    # Group by weekday and rename date column
    if groupBy:
        dataToPlot = dataToPlot.groupby(stats['date'].dt.weekday).mean()
        dataToPlot = dataToPlot.reset_index().rename(columns={'date':'weekday'})

    # change stats from columns to row attribute
    dataToPlot = pd.melt(dataToPlot, id_vars=['weekday'], value_vars=columns,
                         var_name='stats', value_name='val')
    # Rename stats and weekdays
    dataToPlot['stats'].replace(NAMES, inplace=True)
    dataToPlot['weekday'].replace(dayOfWeek, inplace=True)
    # Plot
    g = sns.factorplot(data=dataToPlot, x="weekday", y="val", col="stats",
                       order=dayOfWeekOrder, kind="point", sharey=False, col_wrap=3)
    g.set_xticklabels(rotation=45)
    g.set(xlabel='')
    return g
    #sns.plt.show() 
开发者ID:5agado,项目名称:fitbit-analyzer,代码行数:22,代码来源:plotting.py

示例2: test_groupby

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import groupby [as 别名]
def test_groupby(self):
        with tm.assert_produces_warning(FutureWarning,
                                        check_stacklevel=False):
            pd.groupby(pd.Series([1, 2, 3]), [1, 1, 1]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:6,代码来源:test_api.py

示例3: _prepareWeekdayByMonthStats

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import groupby [as 别名]
def _prepareWeekdayByMonthStats(stats):
    # Add day and month columns, and groupby
    stats = stats.copy()
    stats['day'] = stats['date'].dt.weekday
    stats['month'] = stats['date'].dt.month
    dataToPlot = stats.groupby(['day', 'month']).mean()

    dataToPlot = dataToPlot.reset_index()
    dataToPlot['day'].replace(dayOfWeek, inplace=True)
    dataToPlot['month'].replace(months, inplace=True)

    return dataToPlot

# def plotWeekdayStats(stats, columns):
#     """
#     Plot aggregated (mean) stats by dayOfWeek
#     :param stats: data to plot
#     :param columns: columns from stats to plot
#     """
#     MEASURE_NAME = 'weekday'
#     dayOfWeek={0:'Mon', 1:'Tue', 2:'Wed', 3:'Thur', 4:'Fri', 5:'Sat', 6:'Sun'}
#     order = ['Mon','Tue','Wed','Thur','Fri','Sat','Sun']
#     stats[MEASURE_NAME] = stats[MEASURE_NAME].map(dayOfWeek)
#
#     f, axes = getAxes(2,2)
#     for i, c in enumerate(columns):
#         if c in NAMES:
#             c = NAMES[c]
#         g = sns.barplot(x=MEASURE_NAME, y=c, data=stats, order=order, ax=axes[i])
#         g.set_xlabel('')
#     sns.plt.show()
#     #plot(stats, columns, MEASURE_NAME, 2, 3, order=order) 
开发者ID:5agado,项目名称:fitbit-analyzer,代码行数:34,代码来源:plotting.py

示例4: _prepareYearAndMonthStats

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import groupby [as 别名]
def _prepareYearAndMonthStats(stats, columns):
    # Group by month and change stats from columns to row attribute
    dataToPlot = stats.groupby(stats['date'].dt.to_period("M")).mean()
    dataToPlot = pd.melt(dataToPlot.reset_index(), id_vars=['date'], value_vars=columns,
                         var_name='stats', value_name='val')
    # Rename stats
    dataToPlot['stats'].replace(NAMES, inplace=True)
    return dataToPlot 
开发者ID:5agado,项目名称:fitbit-analyzer,代码行数:10,代码来源:plotting.py

示例5: plotDailyStatsHb

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import groupby [as 别名]
def plotDailyStatsHb(data):
    ax = data.groupby(data[hbStats.NAME_DT_COL].dt.date).mean().plot()
    #data.groupby(data[hbStats.NAME_DT_COL].dt.date).mean().rolling(30).mean().plot(ax=ax)
    sns.plt.show() 
开发者ID:5agado,项目名称:fitbit-analyzer,代码行数:6,代码来源:plotting.py

示例6: _plotMonthlyStats

# 需要导入模块: import pandas [as 别名]
# 或者: from pandas import groupby [as 别名]
def _plotMonthlyStats(stats, columns, groupBy=True):
    dataToPlot = stats.copy()
    # Group by month and rename date column
    if groupBy:
        dataToPlot = dataToPlot.groupby(stats['date'].dt.month).mean()
        dataToPlot = dataToPlot.reset_index().rename(columns={'date': 'month'})

    # change stats from columns to row attribute
    dataToPlot = pd.melt(dataToPlot, id_vars=['month'], value_vars=columns,
                         var_name='stats', value_name='val')
    # Rename stats and weekdays
    dataToPlot['stats'].replace(NAMES, inplace=True)
    dataToPlot['month'].replace(months, inplace=True)
    order = [m for m in monthsOrder if m in dataToPlot['month'].unique()]
    # Plot
    g = sns.factorplot(data=dataToPlot, x="month", y="val", col="stats", order=order, kind="bar", sharey=False)
    g.set_xticklabels(rotation=45)
    g.set(xlabel='')
    return g
    #sns.plt.show()

# def _plotMonthlyStats(stats, columns):
#     """
#     Plot aggregated (mean) stats by month
#     :param stats: data to plot
#     :param columns: columns from stats to plot
#     """
#     MEASURE_NAME = 'month'
#     months={1:'Jan', 2:'Feb', 3:'Mar', 4:'Apr', 5:'May', 6:'Jun', 7:'Jul', 8:'Aug',
#             9:'Sep', 10:'Oct', 11:'Nov', 12:'Dec'}
#     order = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
#     stats[MEASURE_NAME] = stats[MEASURE_NAME].map(months)
#
#     order = [m for m in order if m in stats[MEASURE_NAME].unique()]
#
#     f, axes = getAxes(2,2)
#     for i, c in enumerate(columns):
#         if c in NAMES:
#             c = NAMES[c]
#         g = sns.barplot(x=MEASURE_NAME, y=c, data=stats, order=order, ax=axes[i])
#         g.set_xlabel('')
#     sns.plt.show() 
开发者ID:5agado,项目名称:fitbit-analyzer,代码行数:44,代码来源:plotting.py


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