Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

python - Compare one by one a float number from a list to a column in a dictionary between a range

I'm trying to compare each number from a list to an set of elements in a column from a dictionary, if value from list is between a range from one of the elements of the column from a dictionary I want to ad it's correspondent from another column to a new list.

Current result is not adding all corresponding values or doing un expecting additions

Here some of my code, current results are not as expected

#Open CSV file as a dictionary
fname2=input('Enter Tme vs Depth File name ')
with open(fname2, 'r') as csv_file2:
    handler2=csv.DictReader(csv_file2)
    temp=[]
#Arr = Array with the comparisson values, first input
    for n in Arr:   
        m=float(n)
#limits for the range
        x=m-0.5
        y=m+0.5
        for line in handler2:
            if (float(line['Date/Time']) > x) and (float(line['Date/Time']) < y) :
                if float(line['RSSDEP_CONT_RT']) in temp:
                    continue
                else:
                    temp.append(float(line['RSSDEP_CONT_RT']))
# print New list 
print (len(temp))

Thanks in advance


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...