(编辑:jimmy 日期: 2024/11/16 浏览:2)
python提取特定时间段内的数据
尝试一下:
data['Date'] = pd.to_datetime(data['Date']) data = data[(data['Date'] >=pd.to_datetime('20120701')) & (data['Date'] <= pd.to_datetime('20120831'))]
实际测试
''' Created on 2019年1月3日 @author: hcl ''' import pandas as pd import matplotlib.pyplot as plt data_path = 'one_20axyz.csv' if __name__ == '__main__': msg = pd.read_csv(data_path) # ID_set = set(msg['Time'].tolist()) # ID_list = list(ID_set) # print(len(msg['Time'].tolist()),len(ID_list),len(msg['Time'].tolist())/len(ID_list))#打印数据量 多少秒 平均每秒多少个 # print(msg.head(10)) # left_a = msg[msg['leg'] == 1]['az'] # right_a = msg[msg['leg'] == 2]['az'] # plt.plot(left_a,label = 'left_a') # plt.plot(right_a,label = 'right_a') # plt.legend(loc = 'best') # plt.show() left_msg = msg[msg['leg'] == 1] #DataFrame data = left_msg[(pd.to_datetime(left_msg['Time'] ,format = '%H:%M:%S')>= pd.to_datetime('16:23:42',format = '%H:%M:%S')) & (pd.to_datetime(left_msg['Time'] ,format = '%H:%M:%S') <= pd.to_datetime('16:23:52',format = '%H:%M:%S'))] # print(msg.head()) print(data)
输出:
Time ID leg ax ay az a Rssi 1 16:23:42 5 1 0.6855 -0.6915 0.1120 0.980116 -34 3 16:23:42 5 1 0.6800 -0.6440 0.1365 0.946450 -31 5 16:23:42 5 1 0.7145 -0.7240 0.1095 1.023072 -34 7 16:23:42 5 1 0.7050 -0.6910 0.1080 0.993061 -30 9 16:23:42 5 1 0.7120 -0.6400 0.0920 0.961773 -31 10 16:23:42 5 1 0.7150 -0.6810 0.1290 0.995805 -34 12 16:23:42 5 1 0.7250 -0.6655 0.1890 1.002116 -32 13 16:23:42 5 1 0.7160 -0.7065 0.1000 1.010840 -31 15 16:23:42 5 1 0.7545 -0.6990 0.1715 1.042729 -30 17 16:23:42 5 1 0.7250 -0.6910 0.1325 1.010278 -31 19 16:23:42 5 1 0.7520 -0.7260 0.1820 1.060992 -33 21 16:23:42 5 1 0.7005 -0.7150 0.0605 1.002789 -33 23 16:23:42 5 1 0.7185 -0.6630 0.1430 0.988059 -30 25 16:23:42 5 1 0.7170 -0.7040 0.0920 1.009044 -34 27 16:23:42 5 1 0.7230 -0.6810 0.1060 0.998862 -31 29 16:23:42 5 1 0.7230 -0.6720 0.0940 0.991539 -31 31 16:23:42 5 1 0.6955 -0.6975 0.0720 0.987629 -33 32 16:23:42 5 1 0.7430 -0.6895 0.1495 1.024602 -34 34 16:23:43 5 1 0.7360 -0.6855 0.1200 1.012920 -32 36 16:23:43 5 1 0.7160 -0.7000 0.1330 1.010121 -30 38 16:23:43 5 1 0.7095 -0.7165 0.1090 1.014221 -31 40 16:23:43 5 1 0.7195 -0.6895 0.1270 1.004599 -34 44 16:23:43 5 1 0.7315 -0.6855 0.1000 1.007473 -34 46 16:23:43 5 1 0.7240 -0.7020 0.0960 1.013013 -31 48 16:23:43 5 1 0.7240 -0.7010 0.0970 1.012416 -32 50 16:23:43 5 1 0.7380 -0.6820 0.1480 1.015713 -34 52 16:23:43 5 1 0.7285 -0.6990 0.0990 1.014453 -33 53 16:23:43 5 1 0.7160 -0.7005 0.1630 1.014852 -30 55 16:23:43 5 1 0.7175 -0.6940 0.0735 1.000922 -29 57 16:23:43 5 1 0.7140 -0.7170 0.0960 1.016416 -28 .. ... .. ... ... ... ... ... ... 285 16:23:51 5 1 0.0550 -1.0205 0.0955 1.026433 -35 287 16:23:51 5 1 0.0670 -1.0175 0.0915 1.023801 -22 289 16:23:51 5 1 0.0595 -1.0090 0.1025 1.015937 -24 291 16:23:51 5 1 0.0605 -0.9970 0.0905 1.002925 -32 293 16:23:51 5 1 0.0650 -1.0185 0.0740 1.023251 -31 295 16:23:51 5 1 0.0595 -0.9915 0.0945 0.997769 -35 298 16:23:51 5 1 0.0420 -1.0105 0.0970 1.016013 -18 300 16:23:51 5 1 0.0545 -1.0440 0.0795 1.048440 -21 302 16:23:51 5 1 0.0460 -0.9915 0.0765 0.995510 -30 304 16:23:51 5 1 0.0650 -1.0100 0.0810 1.015326 -30 306 16:23:51 5 1 0.0530 -1.0240 0.0765 1.028220 -34 308 16:23:51 5 1 0.0490 -1.0060 0.0785 1.010247 -21 310 16:23:52 5 1 0.0490 -1.0155 0.0760 1.019518 -24 312 16:23:52 5 1 0.0370 -0.9870 0.0660 0.989896 -30 313 16:23:52 5 1 0.0400 -1.0185 0.0435 1.020213 -30 314 16:23:52 5 1 0.0450 -1.0070 0.0540 1.009450 -34 316 16:23:52 5 1 0.0420 -0.9800 0.0595 0.982703 -34 318 16:23:52 5 1 0.0400 -1.0000 0.0595 1.002567 -20 320 16:23:52 5 1 0.0355 -1.0025 0.0635 1.005136 -20 322 16:23:52 5 1 0.0430 -0.9940 0.0735 0.997641 -30 324 16:23:52 5 1 0.0480 -1.0135 0.0640 1.016652 -33 326 16:23:52 5 1 0.0440 -1.0035 0.0670 1.006696 -33 328 16:23:52 5 1 0.0455 -1.0090 0.0600 1.011806 -21 330 16:23:52 5 1 0.0420 -1.0005 0.0605 1.003207 -15 332 16:23:52 5 1 0.0510 -1.0165 0.0670 1.019981 -29 334 16:23:52 5 1 0.0300 -1.0040 0.0460 1.005501 -30 336 16:23:52 5 1 0.0370 -1.0130 0.0500 1.014908 -34 338 16:23:52 5 1 0.0500 -1.0010 0.0530 1.003648 -20 341 16:23:52 5 1 0.0400 -0.9630 0.0615 0.965790 -21 343 16:23:52 5 1 0.0365 -1.0295 0.0410 1.030962 -30 [176 rows x 8 columns]
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接