У меня есть сценарий python для создания коробчатых диаграмм из листа .csv. Все работает нормально, если я анализирую данные без классификации. Затем я классифицирую коробчатые диаграммы (по 1 коробчатой диаграмме для каждого класса: A, B и C)
Как я могу улучшить сценарий, чтобы получить серию коробчатых диаграмм для каждого класса?
лучше всего С уважением!
import pandas as pd
from matplotlib import pyplot
import matplotlib.pyplot as plt
def get_box_plot_data(labels, bp):
rows_list = []
for i in range (len(labels)):
dict1 = {}
dict1['label']= labels[i]
dict1['lower_whisker'] = bp['whiskers'][i*2].get_ydata()[1]
dict1['lower_quartile'] = bp['boxes'][i].get_ydata()[1]
dict1['median'] = bp['medians'][i].get_ydata()[1]
dict1['upper_quartile'] = bp['boxes'][i].get_ydata()[2]
dict1['upper_whisker'] = bp['whiskers'][(i*2)+1].get_ydata()[1]
rows_list.append(dict1)
return pd.DataFrame(rows_list)
filename = 'dataset2.csv'
data = pd.read_csv(filename)
#P1= data['01'].values
data1= data['value1'].values
data2= data['value2'].values
data3= data['value3'].values
data4= data['value4'].values
data5 = data['value5'].values
labels = ['data1','data2','data3','data4','data5']
bp = plt.boxplot([data1,data2,data3,data4,data5],labels=labels)
print(get_box_plot_data(labels, bp))
pyplot.show()
Это значения из моего csv-файла
value1,value2,value3,value4,value5, class
1.8,1.97,1.6,1.55,1.08,A
-0.07,-0.13,0.24,0.13,-0.29
1.34,1.43,1.17,1.08,0.73,C
0.31,0.55,-0.32,-0.13,-0.31,B
0.36,0.35,0.42,0.35,0.11,C
0.0,0.23,0.45,0.37,-0.08,C
-0.3,-0.5,-0.81,-0.87,-1.66,A
1.79,1.76,1.93,1.88,1.78,A
-0.55,-0.51,-0.12,0.11,0.04,B
0.68,0.87,0.72,0.47,0.53,C
2.83,2.88,2.3,2.36,2.05,B
0.24,0.44,0.04,0.06,0.25,A
1.23,1.38,1.37,1.34,1.21,A
0.68,0.65,0.35,0.19,-0.29,C
-0.32,0.26,-0.17,-0.12,-0.29,B
0.43,0.69,0.55,0.45,0.04,C
-0.23,0.02,-0.65,-0.66,-0.68,A
1.1,1.2,0.95,1.0,0.52,B
-0.5,-0.68,-0.33,-0.36,-0.68,A
0.34,0.33,0.35,0.4,0.36,A
0.1,0.36,-0.08,-0.24,-0.31,B
0.76,0.89,1.48,1.38,0.89,C
-0.07,0.06,0.08,0.18,0.02,C
-0.07,0.01,-0.12,-0.25,-0.4,A
0.93,1.04,0.89,0.87,0.38,B
1.56,1.6,1.37,1.4,0.99,C
0.25,0.45,0.63,0.63,0.45,A
0.04,-0.03,0.77,0.77,1.12,C
0.33,0.61,0.84,0.79,0.59,C
-0.16,-0.15,-0.54,-0.66,-0.59,A
-0.24,0.35,-0.12,-0.07,-0.08,A
1.36,1.39,1.62,1.41,1.08,C