鱼C论坛

 找回密码
 立即注册
查看: 1032|回复: 1

怎么根据时间间隔提取数据?

[复制链接]
发表于 2020-3-19 22:03:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
亲,假设要提取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()[1]
    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']
[125.1, 32.175283, 118.757183, 413831224.0, '2018-08-16 14:40:10+08', 0.0, '2018-08-16 14:40:10', 'not defined', 18.0, '', '', 0.0, 1.0, '01010000009485AFAF75B05D40BB4560AC6F164040', '', '']
[125.0, 32.175283, 118.757183, 413831224.0, '2018-08-16 14:40:10+08', 0.0, '2018-08-16 14:40:10', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000009485AFAF75B05D40BB4560AC6F164040', '', '']
[336.0, 32.213933, 118.854787, 412476540.0, '2018-08-16 14:40:11+08', 4.0, '2018-08-16 14:40:11', 'under way using engine', 1.0, '', '', 0.0, 1.0, '0101000000F18288D4B4B65D4080441328621B4040', '', '']
[244.0, 32.168498, 118.845018, 413834795.0, '2018-08-16 14:40:11+08', 2.0, '2018-08-16 14:40:11', 'under way using engine', 1.0, '', '', 0.0, 1.0, '010100000001A260C614B65D4080B8AB5791154040', '', '']
[260.0, 32.183457, 118.930137, 413791519.0, '2018-08-16 14:40:12+08', 3.0, '2018-08-16 14:40:12', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000002CF3565D87BB5D40739CDB847B174040', '', '']
[228.1, 32.140415, 118.7841, 412423210.0, '2018-08-16 14:40:12+08', 5.4, '2018-08-16 14:40:12', 'not defined', 18.0, '', '', 0.0, 1.0, '0101000000CA32C4B12EB25D40156F641EF9114040', '', '']
[92.0, 32.180378, 118.89835, 412550590.0, '2018-08-16 14:40:13+08', 9.0, '2018-08-16 14:40:13', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000002497FF907EB95D407D7555A016174040', '', '']
[150.0, 32.217943, 118.850623, 413800592.0, '2018-08-16 14:40:13+08', 5.0, '2018-08-16 14:40:13', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000006D8E739B70B65D4031B2648EE51B4040', '', '']
[223.2, 32.152767, 118.796947, 412036908.0, '2018-08-16 14:40:14+08', 4.9, '2018-08-16 14:40:14', 'moored', 1.0, '', '', -128.0, 1.0, '01010000004D69FD2D01B35D403A747ADE8D134040', '', '']
[223.0, 32.152767, 118.796947, 412036908.0, '2018-08-16 14:40:14+08', 4.0, '2018-08-16 14:40:14', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000004D69FD2D01B35D403A747ADE8D134040', '', '']
[99.0, 32.1747, 118.933283, 413996034.0, '2018-08-16 14:40:14+08', 11.0, '2018-08-16 14:40:14', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000006BBA9EE8BABB5D403C4ED1915C164040', '', '']

[280.0, 32.184757, 118.90472, 413861487.0, '2018-08-16 14:40:15+08', 3.0, '2018-08-16 14:40:15', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000006002B7EEE6B95D40815A0C1EA6174040', '', '']
[0.0, 32.175827, 118.76212, 413818567.0, '2018-08-16 14:40:15+08', 0.0, '2018-08-16 14:40:15', 'not defined', 18.0, '', '', 0.0, 1.0, '010100000029E8F692C6B05D407C60C77F81164040', '', '']
[0.0, 32.175827, 118.76212, 413818567.0, '2018-08-16 14:40:15+08', 0.0, '2018-08-16 14:40:15', 'under way using engine', 1.0, '', '', 0.0, 1.0, '010100000029E8F692C6B05D407C60C77F81164040', '', '']
[160.0, 32.20256, 118.85788, 412000000.0, '2018-08-16 14:40:15+08', 15.0, '2018-08-16 14:40:15', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000001EF98381E7B65D4027BD6F7CED194040', '', '']
[63.2, 32.126083, 118.759907, 413822854.0, '2018-08-16 14:40:16+08', 8.3, '2018-08-16 14:40:16', 'not defined', 18.0, '', '', 0.0, 1.0, '01010000001840F850A2B05D4071CADC7C23104040', '', '']
[63.0, 32.126083, 118.759907, 413822854.0, '2018-08-16 14:40:16+08', 8.0, '2018-08-16 14:40:16', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000001840F850A2B05D4071CADC7C23104040', '', '']
[0.0, 32.172025, 118.862855, 413769236.0, '2018-08-16 14:40:17+08', 0.0, '2018-08-16 14:40:17', 'under way using engine', 1.0, '', '', 0.0, 1.0, '01010000002A8C2D0439B75D40158C4AEA04164040', '', '']
[254.9, 32.227337, 118.78788, 413764207.0, '2018-08-16 14:40:17+08', 3.7, '2018-08-16 14:40:17', 'not defined', 18.0, '', '', 0.0, 1.0, '01010000000A4B3CA06CB25D40DB15FA60191D4040', '', '']
[]

Process finished with exit code 0
现在要要提取2018-08-16 14:40:11到2018-08-16 14:40:14这段时间间隔的数据,应该怎么搞啊?要根据时间间隔提取
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-3-20 01:04:16 | 显示全部楼层
试试看比较时间:
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是你记录日期的字段,如果不是日期型就转换一下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-25 03:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表