我已经获得了这部分代码,其中使用input
命令我创建了一个小模块,我可以在其中选择所需的文件。现在我需要通过添加一些循环来改进该模块?我猜。我需要的是:
Station
我Date
之后我输入了2015-07-19
所需的日期,这也可以正常使用。我做了一个类似Start_time
和End_time
的变量,但我不知道如何将它放入我的代码中。
概述: 我需要一个函数,它将逐个打开所需时间间隔的文件。后来在我的代码中有情节等,但我没有把它们放在这里使这个问题更清楚。
# Input variables
h = "Hylaty"
u = 'Hugo'
p = 'Patagonia'
Station = input('Enter a station name (Hylaty = h, Hugo = u, Patagonia = p): ')
Date = raw_input('Enter date time (yyyy-mm-dd): ')
Time = raw_input('Enter time (hh-mm): ')
Start_time = input('Enter start time: ')
End_time = input('Enter end time: ')
data = testInstance.convert(r"/Database/Python/Data/Willy/{0}/{1}/".format(Station,Date), "{0}{1}".format(Date,Time),conversionError)
end = time.time()
print("time elapsed " + str(end - start))
答案 0 :(得分:1)
生成时间范围使用pandas
:
import pandas as pd
my_ranges = pd.date_range('2015-07-19', '2015-07-20', freq='5S')
此示例将输出:
In []: my_ranges
Out[]:
DatetimeIndex(['2015-07-19 00:00:00', '2015-07-19 00:00:05',
'2015-07-19 00:00:10', '2015-07-19 00:00:15',
'2015-07-19 00:00:20', '2015-07-19 00:00:25',
'2015-07-19 00:00:30', '2015-07-19 00:00:35',
'2015-07-19 00:00:40', '2015-07-19 00:00:45',
...
'2015-07-19 23:59:15', '2015-07-19 23:59:20',
'2015-07-19 23:59:25', '2015-07-19 23:59:30',
'2015-07-19 23:59:35', '2015-07-19 23:59:40',
'2015-07-19 23:59:45', '2015-07-19 23:59:50',
'2015-07-19 23:59:55', '2015-07-20 00:00:00'],
dtype='datetime64[ns]', length=17281, freq='5S')
可通过索引访问,并可通过所有pandas方法切片,以便提取数据集中的并行范围。
答案 1 :(得分:0)
Date = raw_input('Enter date time (yyyy-mm-dd): ')
Start_time_hours = int(raw_input('Enter start time (hh): ' ))
Start_time_minutes = int(raw_input('Enter start time (mm): ' ))
End_time_hours = int(raw_input('Enter end time (hh): ' ))
End_time_minutes = int(raw_input('Enter end time (mm): ' ))
Start_time_hours += (Start_time_minutes / 60)
Start_time_minutes %= 60
str(Start_time_minutes)
str(Start_time_hours)
str(End_time_minutes)
str(End_time_hours)
Start_time_hours_format = '{:02}'.format(Start_time_hours)
Start_time_minutes_format = '{:02}'.format(Start_time_minutes)
End_time_hours_format = '{:02}'.format(End_time_hours)
End_time_minutes_format = '{:02}'.format(End_time_minutes)
int(Start_time_minutes)
Start_time_minutes += 5
此代码解决了我的问题。