I have to read a comma-separated text file that looks like this:
ID, x, y, soil_temp
1, 10, 6, 8
2, 21, 11, 12
3, 11, 7, 7
4, 32, 12, 8
5, 9, 29, 6
6, 17, 16, 9
7, 22, 9, 11
8, 14, 31, 7
9, 26, 21, 6
10, 19, 19, 10
And thereafter I have to print the columns ID and soil_temp and all the lines with soil temperature above 10. So the result should look something like this:
ID, soil_temp
2, 12
7, 11
Important! No modules should be needed such as pandas and cv, which makes the exercise frustrating for me. It is probably quite easy for most people here.
So I have made a code that looks like this to be able to print the column with soil_temp
:
tempLine = []
with open('soil_temp.txt', 'r') as f:
read_data = f.readlines()
for line in read_data:
line.split()
tempLine.append(line.split())
for item in tempLine:
print(item[3])
This code is also based on advices given in the exercise. My problem is that if I want to only print the lines above 10, I would think a simple if
statement in the last part of the code, something like this would make sense:
for item in tempLine:
if item[3] > 10
print(item[3])
But of course this does not work since the data is stored as strings. I have tried different solutions to change them into integers but since it is multiple strings, I can't find a solution.