plot_activity.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:waffle-reviewer 作者: gabraganca 项目源码 文件源码
def get_daily_gain(data, timezone=pytz.timezone('US/Pacific')):
    """Obtain the daily gain.

    Attributes
    ----------
    data: list
        The list of dictionaries where each dictionary gives information on one
        completed submission. It is the output of the `get_data` function

    timezone: pytz.timezone
        A valid pytz timezone. Default is the Pacific Standard Time, which is
        the one used by Udacity

    Returns
    -------
        A Pandas Series where the indices are the days and the values are the
        total gain in USD of that day. The time zone is the Pacific Standard
        Time.
    """

    date_price_data = np.array([(d['completed_at'], d['price']) for d in data])

    price_series = pd.Series(date_price_data[:, 1].astype(float),
                             index=pd.to_datetime(date_price_data[:, 0]))
    price_series = price_series.sort_index()

    # Convert timezone
    utc = pytz.utc
    price_series = price_series.tz_localize(utc).tz_convert(timezone)


    # Calculate the gain by day
    daily_gain = price_series.groupby(pd.TimeGrouper('D')).sum()

    return daily_gain
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号