jeudi 20 août 2020

If value are not in range Python

I am trying to divide data into categories based on values. So values higher then -25 gets assigned bear level 0 and so on. But when i look at the data I can see that there are values lower then -25 that gets assigned bear level 0. And this is so for all of the categories.

###############################################################
Bear_level = ['high', 'medium-high', 'medium', 'medium-low', 'low', 'very-low']

Level=[]
for value in data_shifted[k]['SCI300max [um]']:
    if value >= -25:
        Level.append(Bear_level[0])
    elif value < -25 and value >= -50:
        Level.append(Bear_level[1])
    elif value < -50 and value >= -75:
        Level.append(Bear_level[2])
    elif value < -75 and value >= -100:
        Level.append(Bear_level[3])
    elif value < -100 and value >= -150:
        Level.append(Bear_level[4])
    else:
        Level.append(Bear_level[5])

Amount = 0
for i in Bear_level:
    for m in range(int(len(Level))):
        if Level[m] ==i:
            Amount += 1
    print(Amount)
    Amount = 0    

for k in data_shifted:
    data_shifted[k]['Bear Level']= Level


data_interp={k:[] for k in progression}   
for k in data_interp:
    data_interp[k]=data_shifted[k][['Chainage [m]', 'Driving Speed [m/s]', 'Latitude', 'Longitude', 'Road temperature [C]', 'Air temperature [C]','Temp corrected Bells2_50','Load Left [kg]','Load Right [kg]', 'Dmax [um]', 'D0 [um]', 'D300 [um]', 'D600 [um]', 'D900 [um]', 'D1200 [um]', 'D1500 [um]', 'SCI300max [um]','SCI300 [um]','SCI300diff [um]', 'SCI600max [um]','SCI600 [um]', 'SCI900max [um]','SCI900 [um]', 'SCI600max-SCI300max [um]', 'SCI900max-SCI600max [um]','speedfilter', 'Bear Level', 'Traffic [ESALs x day]', 'Layer1 Thickness [m]']]
    data_interp[k]= data_interp[k][data_interp[k]['speedfilter']=='Pass']    

all_data_list = [ v for k,v in data_interp.items()] 
all_data = pd.concat(all_data_list ,axis=0)

all_data.to_csv("all_data.csv", index=True, header=True)##### generate csv file with all data

H_bear_section = all_data[all_data['Bear Level'] == Bear_level[0]]
MH_bear_section = all_data[all_data['Bear Level'] == Bear_level[1]]
M_bear_section = all_data[all_data['Bear Level'] == Bear_level[2]]
ML_bear_section = all_data[all_data['Bear Level'] == Bear_level[3]]
L_bear_section = all_data[all_data['Bear Level'] == Bear_level[4]]
VL_bear_section = all_data[all_data['Bear Level'] == Bear_level[5]]

####### Correlations analysis##################

I hope that there are someone that are able to see the problem, as I am lost in for ideas.

Aucun commentaire:

Enregistrer un commentaire