numpy - Resort python list for boxplots -


i want create boxplots of values @ ranges. data comes textfile, looks that:

range;int 3;200 3;200 3;200 3;200 3;200 3;200 3;100 3;200 3;200 5;400 5;400 5;400 5;400 5;400 5;400 5;300 5;400 5;400 5;400 5;400 5;400 5;400 5;400 5;300 5;400 

first row range, second rows values. notice, first row contains duplicates. read in :

 data = np.genfromtxt('out.txt', delimiter=';', names=true, dtype= int)   

if try use data in

fig, ax = plt.subplots() ax.boxplot(data['range'], patch_artist=true) plt.show() 

it make 1 boxplot 'int'. how resort data or adjust skript in order achieve boxplot each unique range?

to re-sort data, can use python's built-in sorted function:

data = np.genfromtxt('out.txt', delimiter=';', names=true, dtype=int) data_sorted = sorted(data, key=lambda value: (value[0], value[1])) 

edit after comment dh81 above:

if looking sorted data within each range, find distinct range values , create dictionary sorted arrays. here came with:

import numpy np  # , sort data data = np.genfromtxt('out.txt', delimiter=';', names=true, dtype=int) data_sorted = sorted(data, key=lambda value: (value[0], value[1]))  # prepare dictionary hold different arrays data_dict = {}  # find different ranges needed range_keys = set([i[0] in data])  # populate each range values range_key in range_keys:     range_values = []     data_point in data_sorted:         if data_point[0] == range_key:             range_values.append(data_point)     data_dict.update({range_key: range_values})  print("got dictionary of arrays: {}".format(data_dict)) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -