Use python to read Excel files and convert to time format

Use Excel as a configuration file to adjust parameters and convert them to real-time parameters:

naclo_reduce_ratio = pd.read_excel('./config/naclo_reduce_ratio.xlsx', header=0)  # col_name = ['Time', 'r1', 'r2']

time_lst = []
for i, row in naclo_reduce_ratio.iterrows():
    now_time_lst = str(row['Time']).split('.')
    time_key = datetime(year=now_temp.year, month=now_temp.month, day=now_temp.day, hour=int(now_time_lst[0]),
                        minute=int(eval('0.' + now_time_lst[1])*60))
    r1 = row['r1']
    r2 = row['r2']
    time_lst.append([time_key, r1, r2])

# print(f'查看使用的time_lst:{time_lst}')
for index, time in enumerate(time_lst[:-1]):
    if time_lst[index][0] <= now_temp < time_lst[index + 1][0]:
        r_1 = time_lst[index][1]
        r_2 = time_lst[index][2]
        print(f'查看实时时间:{now_temp}, t1:{time_lst[index][0]},t2:{time_lst[index + 1][0]}, r1:{r_1}, r2: {r_2}')

Configuration file, pay attention to the file name when importing:

 

Guess you like

Origin blog.csdn.net/March_A/article/details/132014908