I have a text file called data.txt containing tabular data look like this:
PERIOD
CHANNELS 1 2 3 4 5
0 1.51 1.61 1.94 2.13 1.95
5 1.76 1.91 2.29 2.54 2.38
6 2.02 2.22 2.64 2.96 2.81
7 2.27 2.52 2.99 3.37 3.24
8 2.53 2.83 3.35 3.79 3.67
9 2.78 3.13 3.70 4.21 4.09
10 3.04 3.44 4.05 4.63 4.53
In the CHANNELS column are the channel numbers of an instrument and in the other 5 columns are the maximum energy that that particular channel can detect in periods 1, 2, 3, 4 and 5 respectively.
I want to write a python code which gets the inputs: Period, Lower energy and Higher energy from the user and then gives out the channel numbers corresponding to the Lower energy and Higher energy for a given period.
For example:
Enter the period:
>>1
Enter the Lower energy:
>1.0
Enter the Higher energy:
>2.0
#Output
The lower energy channel is 0
The higher energy channel is 6
This is what I have written so far:
import numpy as np
import pandas as pd
period = int(input('Enter the period: '))
lower_energy = float(input('Enter the lower energy value: '))
higher_energy = float(input('Enter the higher energy value: '))
row_names = [0, 5, 6, 7, 8, 9, 10]
column_names = [1, 2, 3, 4, 5]
data_list = []
with open('data.txt') as f:
lines = f.readlines()[2:]
for line in lines:
arr = [float(num) for num in line.split()[1:]]
data_list.append(arr)
df = pd.DataFrame(data_list, columns=column_names, index=row_names)
print (df, '\n')
print (df[period])
Help me add to this.
2.0for higher energy, shouldn't the higher energy channel returned be5since2.0<2.02in period1? Please clarify.