平均每五分钟数据作为 pandas 数据框中的一个数据点
- 作者: 黄某某007
- 来源: 51数据库
- 2022-11-15
问题描述
我在 Pandas 中有一个这样的数据框
I have a Dataframe in Pandas like this
1. 2013-10-09 09:00:05 2. 2013-10-09 09:01:00 3. 2013-10-09 09:02:00 4. ............ 5. ............ 6. ............ 7. 2013-10-10 09:15:05 8. 2013-10-10 09:16:00 9. 2013-10-10 09:17:00
我想通过平均每 5 分钟的数据并为其形成 1 个数据点来减小数据框的大小..像这样
I would like reduce the size of the Dataframe by averaging every 5 mins data and forming 1 datapoint for it ..like this
1. 2013-10-09 09:05:00 2. 2013-10-09 09:10:00 3. 2013-10-09 09:15:00
有人可以帮我吗?
推荐答案
你可能想看看 pandas.resample:
df['Data'].resample('5Min', how='mean')
或者,因为 how = 'mean' 是默认参数:
or, as how = 'mean' is default parameter:
df['Data'].resample('5Min')
例如:
>>> rng = pd.date_range('1/1/2012', periods=10, freq='Min')
>>> df = pd.DataFrame({'Data':np.random.randint(0, 500, len(rng))}, index=rng)
>>> df
Data
2012-01-01 00:00:00 488
2012-01-01 00:01:00 172
2012-01-01 00:02:00 276
2012-01-01 00:03:00 5
2012-01-01 00:04:00 233
2012-01-01 00:05:00 266
2012-01-01 00:06:00 103
2012-01-01 00:07:00 40
2012-01-01 00:08:00 274
2012-01-01 00:09:00 494
>>>
>>> df['Data'].resample('5Min')
2012-01-01 00:00:00 234.8
2012-01-01 00:05:00 235.4
您可以找到更多示例这里.
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
