Python提取特定时间段内数据的方法实例
时间:2022-04-02 10:26 作者:admin610456
python/' target='_blank'>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 pdimport matplotlib.pyplot as pltdata_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 Rssi1 16:23:42 5 1 0.6855 -0.6915 0.1120 0.980116 -343 16:23:42 5 1 0.6800 -0.6440 0.1365 0.946450 -315 16:23:42 5 1 0.7145 -0.7240 0.1095 1.023072 -347 16:23:42 5 1 0.7050 -0.6910 0.1080 0.993061 -309 16:23:42 5 1 0.7120 -0.6400 0.0920 0.961773 -3110 16:23:42 5 1 0.7150 -0.6810 0.1290 0.995805 -3412 16:23:42 5 1 0.7250 -0.6655 0.1890 1.002116 -3213 16:23:42 5 1 0.7160 -0.7065 0.1000 1.010840 -3115 16:23:42 5 1 0.7545 -0.6990 0.1715 1.042729 -3017 16:23:42 5 1 0.7250 -0.6910 0.1325 1.010278 -3119 16:23:42 5 1 0.7520 -0.7260 0.1820 1.060992 -3321 16:23:42 5 1 0.7005 -0.7150 0.0605 1.002789 -3323 16:23:42 5 1 0.7185 -0.6630 0.1430 0.988059 -3025 16:23:42 5 1 0.7170 -0.7040 0.0920 1.009044 -3427 16:23:42 5 1 0.7230 -0.6810 0.1060 0.998862 -3129 16:23:42 5 1 0.7230 -0.6720 0.0940 0.991539 -3131 16:23:42 5 1 0.6955 -0.6975 0.0720 0.987629 -3332 16:23:42 5 1 0.7430 -0.6895 0.1495 1.024602 -3434 16:23:43 5 1 0.7360 -0.6855 0.1200 1.012920 -3236 16:23:43 5 1 0.7160 -0.7000 0.1330 1.010121 -3038 16:23:43 5 1 0.7095 -0.7165 0.1090 1.014221 -3140 16:23:43 5 1 0.7195 -0.6895 0.1270 1.004599 -3444 16:23:43 5 1 0.7315 -0.6855 0.1000 1.007473 -3446 16:23:43 5 1 0.7240 -0.7020 0.0960 1.013013 -3148 16:23:43 5 1 0.7240 -0.7010 0.0970 1.012416 -3250 16:23:43 5 1 0.7380 -0.6820 0.1480 1.015713 -3452 16:23:43 5 1 0.7285 -0.6990 0.0990 1.014453 -3353 16:23:43 5 1 0.7160 -0.7005 0.1630 1.014852 -3055 16:23:43 5 1 0.7175 -0.6940 0.0735 1.000922 -2957 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 -35287 16:23:51 5 1 0.0670 -1.0175 0.0915 1.023801 -22289 16:23:51 5 1 0.0595 -1.0090 0.1025 1.015937 -24291 16:23:51 5 1 0.0605 -0.9970 0.0905 1.002925 -32293 16:23:51 5 1 0.0650 -1.0185 0.0740 1.023251 -31295 16:23:51 5 1 0.0595 -0.9915 0.0945 0.997769 -35298 16:23:51 5 1 0.0420 -1.0105 0.0970 1.016013 -18300 16:23:51 5 1 0.0545 -1.0440 0.0795 1.048440 -21302 16:23:51 5 1 0.0460 -0.9915 0.0765 0.995510 -30304 16:23:51 5 1 0.0650 -1.0100 0.0810 1.015326 -30306 16:23:51 5 1 0.0530 -1.0240 0.0765 1.028220 -34308 16:23:51 5 1 0.0490 -1.0060 0.0785 1.010247 -21310 16:23:52 5 1 0.0490 -1.0155 0.0760 1.019518 -24312 16:23:52 5 1 0.0370 -0.9870 0.0660 0.989896 -30313 16:23:52 5 1 0.0400 -1.0185 0.0435 1.020213 -30314 16:23:52 5 1 0.0450 -1.0070 0.0540 1.009450 -34316 16:23:52 5 1 0.0420 -0.9800 0.0595 0.982703 -34318 16:23:52 5 1 0.0400 -1.0000 0.0595 1.002567 -20320 16:23:52 5 1 0.0355 -1.0025 0.0635 1.005136 -20322 16:23:52 5 1 0.0430 -0.9940 0.0735 0.997641 -30324 16:23:52 5 1 0.0480 -1.0135 0.0640 1.016652 -33326 16:23:52 5 1 0.0440 -1.0035 0.0670 1.006696 -33328 16:23:52 5 1 0.0455 -1.0090 0.0600 1.011806 -21330 16:23:52 5 1 0.0420 -1.0005 0.0605 1.003207 -15332 16:23:52 5 1 0.0510 -1.0165 0.0670 1.019981 -29334 16:23:52 5 1 0.0300 -1.0040 0.0460 1.005501 -30336 16:23:52 5 1 0.0370 -1.0130 0.0500 1.014908 -34338 16:23:52 5 1 0.0500 -1.0010 0.0530 1.003648 -20341 16:23:52 5 1 0.0400 -0.9630 0.0615 0.965790 -21343 16:23:52 5 1 0.0365 -1.0295 0.0410 1.030962 -30[176 rows x 8 columns]
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对脚本之家的支持。如果你想了解更多相关内容请查看下面相关链接
(责任编辑:admin)