摘要
我有一个.csv文件,其中包含温度值和测量温度时的时间戳。我想做的是找到值在特定值以下完成的时间段。我想在没有数据库的情况下进行操作,我知道使用mysql或其他方法很容易。
这是一个学习python统计信息的私人项目。
数据结构
001,"2018-8-15 08:00:00", 89
002,"2018-8-15 08:00:30", 68
003,"2018-8-15 08:01:00", 56
004,"2018-8-15 08:01:30", 55
005,"2018-8-15 08:02:00", 56
006,"2018-8-15 08:02:30", 63
一个文件每天包含720个条目。
我的主意是什么?
with open('2018815') as file:
for line in files:
s = line.strip().split(",")
if s[3] == "temperature":
continue
if int(s[3]) < 60:
setStart()
if int(s[3]) > 60:
setEnd()
函数
setStart
和setEnd
尚未实现,因为我发现自己的想法有误。当我运行代码并仅打印值时,我发现周期内的周期也定义为周期。我有什么问题
如何跳过时段内的时段?
我可以使用一个库来更轻松地解决此问题吗?
最佳答案
如上所述,pandas是您需要的库,但是如果您想循环使用它,您仍然可以添加一个布尔值,以免在句点中添加开始:
with open('2018815') as file:
is_in_periode = False
for line in files:
s = line.strip().split(",")
if s[3] == "temperature":
continue
if(int(s[3]) < 60 and not is_in_periode):
setStart()
is_in_periode = True
if(int(s[3]) > 60 and is_in_periode):
setEnd()
is_in_periode = False
关于python - 使用python查找.csv文件中的时间段,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51896905/