小编Sna*_*Gee的帖子

在Pandas MultiIndex中重新采样

我有一些分层数据,最终到时间序列数据,看起来像这样:

df = pandas.DataFrame(
    {'value_a': values_a, 'value_b': values_b},
    index=[states, cities, dates])
df.index.names = ['State', 'City', 'Date']
df

                               value_a  value_b
State   City       Date                        
Georgia Atlanta    2012-01-01        0       10
                   2012-01-02        1       11
                   2012-01-03        2       12
                   2012-01-04        3       13
        Savanna    2012-01-01        4       14
                   2012-01-02        5       15
                   2012-01-03        6       16
                   2012-01-04        7       17
Alabama Mobile     2012-01-01        8       18
                   2012-01-02        9       19
                   2012-01-03       10       20
                   2012-01-04       11       21
        Montgomery 2012-01-01       12       22
                   2012-01-02       13       23
                   2012-01-03       14       24
                   2012-01-04       15       25
Run Code Online (Sandbox Code Playgroud)

我想对每个城市进行时间重新采样,所以就像这样

df.resample("2D", how="sum")
Run Code Online (Sandbox Code Playgroud)

会输出 …

python time-series hierarchical-data pandas

42
推荐指数
5
解决办法
2万
查看次数

标签 统计

hierarchical-data ×1

pandas ×1

python ×1

time-series ×1