python - 如何从数据框中选择具有相同日期时间的数据?
问题描述
我正在使用熊猫分析遥测数据。数据保存在 HDF5 文件中。当然,数据也有保存的时候。所以我的问题是如何从日期帧(甚至秒)中提取具有相同日期时间的数据?例如数据如下所示:
943 Power.PDM_1__PDM_Temperature_degC 2019-06-13 00:17:50 8.965
944 Power.PDM_2__PDM_Current_A 2019-06-13 00:17:50 0.174
945 Power.BCM0_Battery_Interface_Plate_Temp_degC 2019-06-13 00:18:20 19.829
946 Power.BCM1_Battery_Cell_Temperature_degC 2019-06-13 00:18:20 79.146
947 Power.BCM2_Battery_Cell_Temperature_degC 2019-06-13 00:18:20 81.280
948 Power.BCR0__Array_Current_mA 2019-06-13 00:18:20 561.000
949 Power.BCR0__Array_Temperature_degC 2019-06-13 00:18:20 5.920
所以如果数据是 2019-06-13 00:18:20,我希望只有这个数据:
945 Power.BCM0_Battery_Interface_Plate_Temp_degC 2019-06-13 00:18:20 19.829
946 Power.BCM1_Battery_Cell_Temperature_degC 2019-06-13 00:18:20 79.146
947 Power.BCM2_Battery_Cell_Temperature_degC 2019-06-13 00:18:20 81.280
948 Power.BCR0__Array_Current_mA 2019-06-13 00:18:20 561.000
949 Power.BCR0__Array_Temperature_degC 2019-06-13 00:18:20 5.920
到目前为止我有这个代码:
file = pd.read_hdf('KazSTSAT5.h5', mode = 'r')
#reads HDF5 file
df = pd.DataFrame (file)
#converts UNIX type data to Usual datetime
df['time'] = pd.to_datetime(df['time'],unit='s')
pd.set_option('display.max_rows', None)
timestamp = df.iloc[0, 1]
time = pd.DataFrame()
解决方案
假设您已索引日期列。
ts = pd.Timestamp
print(df.query('time == @ts("20190613T001820")')
推荐阅读
- reactjs - 如何使用扩展运算符更新 React js 中的状态?
- sed - 使用具有多个同名键的 sed 替换 yml 文件的内容
- excel - 将 Office.js(Excel 加载项)连接到 SQL Server
- sql - 如何修复与两个条件匹配的记录的此查询?
- php - PHP7 为所有标准 php 函数添加斜线 php-cs-fixer 规则
- php - Eloquent Collection contains() 有效,但 diff() 或 intersect() 认为一切都不一样
- html - 如何使用AngularJS为不同的点击事件显示一个div?
- php - 无法登录管理员 wordpress:标题之前的脚本输出结束:index.php
- oracle-sqldeveloper - Oracle SQL Developer 中 SQL 代码的缩进和格式化
- javascript - 如何根据复选框动态触发的ajax帖子插入/删除数据(选中或未选中)