怎么根据时间间隔提取数据?
亲,假设要提取2018-08-16 14:40:11到2018-08-16 14:40:14这段时间间隔内的数据,应该怎么搞啊?程序一:通过程序一读取了数据包中的数据
# 对excel的操作
import xlrd
def ais_gain():
# 打开excle
xl = xlrd.open_workbook(r'D:\file\ais.xlsx')
# print(xl.read())
# todo 通过索引获取工作表(从0开始依次为各个工作表)
table = xl.sheets()
print(table)
# 获取一共多少行
rows = table.nrows
print(rows)
# todo 获取指定范围的内容,索引从0开始
for i in range(20):
row = table.row_values(i)
print(row)
ais_gain()
程序二:将程序一中的数据建立了一个列表存起来
import pp_ais_gain
# 记录从ais里面提取到的数据
ais_list = []
def new_ais():
# 使用获取的每一个数据建立一个ais数据字典
for each in pp_ais_gain:
ais_dict = {each}
# 将ais数据字典添加到列表中
ais_list.append(ais_dict)
print(ais_list)
# 打印新的ais_list
print(ais_list)
得到的结果是
D:\python38\python.exe D:/pycharm2019/new.py2020/untitled/pp_ais_dict.py
<xlrd.sheet.Sheet object at 0x00000213A1FD5F10>
1048576
['course(航向)', 'lat(纬度)', 'lon(经度)', 'mmsi(九位码)', 'postime(更新时间)', 'speed(速度)', 'postime(更新时间)', 'shipstatus(船舶状态)', 'messageid', 'postype', 'utc', 'turnrate', 'source', 'geom(空间坐标)', 'geog', 'period']
[]
Process finished with exit code 0
现在要要提取2018-08-16 14:40:11到2018-08-16 14:40:14这段时间间隔的数据,应该怎么搞啊?要根据时间间隔提取 试试看比较时间:
import datetime
begintime = datetime.datetime.strptime('2018-08-16 14:40:11', '%Y-%m-%d %H:%M:%S')
endtime=datetime.datetime.strptime('2018-08-16 14:40:14', '%Y-%m-%d %H:%M:%S')
if begintime<=postime<=endtime: #postime是你记录日期的字段,如果不是日期型就转换一下
页:
[1]