Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
35 lines (27 loc) · 889 Bytes

File metadata and controls

35 lines (27 loc) · 889 Bytes
Copy raw file
Download raw file
Edit and raw actions
@author jackzhenguo
@desc 完成数据下采样,调整步长由小时为天
@tag
@version 
@date 2020/03/20
第 182 个小例子:**完成数据下采样,调整步长由小时为天**

步长为小时的时间序列数据,有没有小技巧,快速完成下采样,采集成按天的数据呢?先生成测试数据:

import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(1,10,size=(240,3)), \
columns = ['商品编码','商品销量','商品库存'])
df.index = pd.util.testing.makeDateIndex(240,freq='H')
df
使用 resample 方法合并为天(D)

小技巧,使用 resample 方法,合并为天(D)

day_df = df.resample("D")["商品销量"].sum().to_frame()
day_df

果如下,10行,240小时,正好为 10 days:

[上一个例子](181.md) [下一个例子](183.md)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.