Python 如何从数据框中选择具有相同日期时间的数据?

Python 如何从数据框中选择具有相同日期时间的数据?,python,pandas,Python,Pandas,我正在用熊猫分析遥测数据。保存在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

我正在用熊猫分析遥测数据。保存在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")')

很可能我没有得到我所期望的。请看一下代码好吗?在将unix时间戳转换为日期格式后,您是否尝试过执行上述操作?另外,我建议使用unix时间戳本身查询数据帧。1547251207.0空数据帧列:[Chu name,time,value]索引:[]