У меня есть набор данных (Образец набора данных)
Contract Sections A001_Average_By_Block A002_Average_By_Block
0 O.U20 O1 0.005 0.002915
1 O.Z20 O1 0.005 0.002915
2 O.H21 O1 0.005 0.002915
3 O.M21 O1 0.005 0.002915
4 O.U21 O2 0.005 0.004443
5 O.Z21 O2 0.005 0.004443
6 O.H22 O2 0.005 0.004443
7 O.M22 O2 0.005 0.004443
8 S3.U20 S3 0.500 0.250000
9 S3.Z20 S3 0.500 0.250000
10 S6.M26 S6 NaN 3.875000
11 S6.U26 S6 NaN 3.875000
12 S6.Z26 S6 NaN 3.875000
13 S6.H27 S6 NaN 3.875000
14 S9.U26 S9 NaN 5.250000
15 S9.Z26 S9 NaN 5.250000
16 F3.U26 F3 2.000 NaN
17 F3.Z26 F3 2.000 NaN
18 F3.H27 F3 2.000 NaN
19 F6.H26 F6 NaN 10.833333
20 F6.M26 F6 NaN 10.833333
21 F6.U26 F6 NaN 10.833333
22 F9.U20 F9 1.500 1.000000
Я пытаюсь построить график гистограммы A001_Average_By_Block
и A002_Average_By_Block
Я могу построить график на основе Контракт, отдельная диаграмма для каждого из продуктов контракта в данных, например диаграмма для O, S, F (и других контрактов в исходном наборе данных), эта только для O.
using the code (please let me know if there is a better way of doing it)
df_O = df[df['Contract'].str.contains('O')]
ax = df_O[['A001','A002']].plot(kind='bar', title ="Outrights - All data points", figsize=(15, 10), legend=True, fontsize=12)
ax.set_xticklabels(df_O['Contract'], rotation=0)
plt.show()
Now what I'm trying to do is create a separate bar chart on the basis of the Section
column. In my case 'O.U20 - O.M21' belongs to O1 block and all of them have the same 'A001_Average_By_Block
' value (same in the case of A002_Average_By_Block
. Using the same above code I get something like

which is obviously not correct as I want only O1 and O2 in the xticker labels and just two corresponding bars that compares the two mentioned column. I tried this code
pd.value_counts(df_O['Sections']).plot.bar()
but it is just counting the number of times O1 and O2 occurs. What I want is that if there are 8 blocks of O (sample data shows just two blocks O1, O2) I can get a graph that looks something like this
How can I achieve the desired charts? Basically the structure of data looks something like this (Hopefully this makes sense now)
введите описание изображения здесь