trending.py 文件源码

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

项目:visualizations 作者: ContentMine 项目源码 文件源码
def update(attrname, old, new):
    subset = get_subset(dictchooser.value)
    new_absolute_source = subset[0] \
                                        .ix[:, :top_n.value] \
                                        .groupby(pd.TimeGrouper(freq=timegroupoptionsmapper[timegroup.active])) \
                                        .sum().fillna(0)
    new_relative_source = subset[1] \
                                        .ix[:, :top_n.value] \
                                        .groupby(pd.TimeGrouper(freq=timegroupoptionsmapper[timegroup.active])) \
                                        .sum().fillna(0)

    for old, new in zip(abs_arrangement, new_absolute_source.columns.tolist()):
        old.title.text = new
    for old, new in zip(rel_arrangement, new_relative_source.columns.tolist()):
        old.title.text = new

    new_abs_sources = [ColumnDataSource(dict(date=new_absolute_source.index,
                                             y=new_absolute_source[l]))
                                                for l in new_absolute_source.columns.tolist()]
    new_rel_sources = [ColumnDataSource(dict(date=new_relative_source.index,
                                             y=new_relative_source[l]))
                                                for l in new_relative_source.columns.tolist()]
    for old, new in zip(abs_sources, new_abs_sources):
        old.data.update(new.data)
    for old, new in zip(rel_sources, new_rel_sources):
        old.data.update(new.data)

    new_abs_point_sources = [ColumnDataSource(dict(date=[new_absolute_source[l].idxmax()],
                                               y=[new_absolute_source[l].max()],
                                               text=[str(int(new_absolute_source[l].max()))]
                                               )
                                          )
                                          for l in new_absolute_source.columns.tolist()]
    new_rel_point_sources = [ColumnDataSource(dict(date=[new_relative_source[l].idxmax()],
                                               y=[new_relative_source[l].max()],
                                               text=[str(int(new_relative_source[l].max()))]
                                               )
                                          )
                                          for l in new_relative_source.columns.tolist()]
    for old, new in zip(abs_point_sources, new_abs_point_sources):
        old.data.update(new.data)
    for old, new in zip(rel_point_sources, new_rel_point_sources):
        old.data.update(new.data)

# Create Input controls
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号