python - How to resample a pandas data frame every half second with data every second?
问题描述
I have a pandas DataFrame like this with time in the index and column A:
A
2018-01-24 00:06:00 3.0
2018-01-24 00:06:01 4.0
2018-01-24 00:06:02 8.0
2018-01-24 00:06:03 4.0
2018-01-24 00:06:04 2.0
I want the data frame to have half second intervals where the half seconds are the averages between the two data points such that I get something like this:
A
2018-01-24 00:06:00 3.0
2018-01-24 00:06:00.500 3.5
2018-01-24 00:06:01 4.0
2018-01-24 00:06:01.500 6.0
2018-01-24 00:06:02 8.0
2018-01-24 00:06:02.500 6.0
2018-01-24 00:06:03 4.0
2018-01-24 00:06:03.500 3.0
2018-01-24 00:06:04 2.0
解决方案
让我们试试resample
interpolate
df=df.resample('500ms').interpolate()
df
A
2018-01-24 00:06:00.000 3.0
2018-01-24 00:06:00.500 3.5
2018-01-24 00:06:01.000 4.0
2018-01-24 00:06:01.500 6.0
2018-01-24 00:06:02.000 8.0
2018-01-24 00:06:02.500 6.0
2018-01-24 00:06:03.000 4.0
2018-01-24 00:06:03.500 3.0
2018-01-24 00:06:04.000 2.0
推荐阅读
- python - 大文本编辑,粘贴替换
- sublimetext3 - 自定义 JSX 的 Emmet 缩写
- c++ - 解决错误:operator[] 不匹配
- aws-lambda - 无法在 AWS Lambda 中初始化 Dialogflow Fulfillment WebhookClient
- android - Gradle 同步失败:原因:未指定 compileSdkVersion
- python - 如何动态查询一个mongoDB文档
- haskell - 组合不同类型的流
- react-native - react-native iOS 生产 JS 包
- sql - 使用 sql 从交易明细中获取贷方和借方
- uwp - 配置 NavigationView 以显示纯文本菜单,而不显示纯图标栏