Home python cycle for building Boxplot

cycle for building Boxplot

Author

Date

Category

I have a data frame, on the basis of which for each characteristic I want to build a box. Column [Sphere] is a factor variable, x axis in a box. When I try to build a bulklot on any particular column – everything turns out perfectly and without problems. But when I start the cycle, to automatically build bouts for all the available steps, it turns out an error.

import seaborn as sns
Import Matplotlib.pyPlot AS PLT
Import Pandas AS PD
DF = PD.Read_excel ('DataFrame throughout the entire field, placed .xlsx', sheet_name = 'all')
For col in df.columns:
  Plt.figure (Figsize = (16, 8))
  x = df ['sphere']
  Y = DF [COL]
  PLT.SUBPLOTS_ADJUST (Bottom = 0.25, Top = 0.79)
  AX = SNS.BOXPLOT (X, Y)
  Plt.xticks (Rotation = 80)
  PLT.DRAW ()
  PLT.Savefig ()

valueerror: neither the x nor y variable appears to be numeric.

Obviously, I miss something important, but I can not understand what. Help me please. What can I fix the boxes to be automatically built in a cycle for each column [characteristic_n], and the column [sphere]

remained a factor variable.

+ ------------------- + --------------- + ------------------ + --------------- --- + ------------------ + ------------------ +
| Sphere | Characteristic_1 | Characteristic_2 | Characteristic_3 | Characteristic_4 | Characteristic_5 |
+ ------------------- + ------------------ + ---------- -------- + ------------------ + ------------------ + --- --------------- +.
| All services | 17 | 22 | 17 | 21 | 17 |
| All services | 36 | 40 | 16 | 4 | 24 |
| All services | 20 | 28 | 22 | 18 | 30 |
| All services | 34 | 36 | 10 | 8 | 20 |
| Registration | 17 | 29 | 22 | 23 | 24 |
| Registration | 28 | 20 | 26 | 12 | 16 |
| Redistribution | 22 | 28 | 24 | 14 | 12 |
| Redistribution | 25 | 35 | 35 | 21 | 17 |
| All services | 23 | 26 | 28 | 17 | 22 |
| Registration | 27 | 27 | 31 | 16 | 12 |
| All services | 29 | 39 | 32 | 23 | 22 |
| Registration | 26 | 29 | 20 | 15 | 24 |
| Registration | 24 | 29 | 16 | 15 | 14 |
| Counseling | 40 | 28 | 28 | 32 | 18 |
| Professional | 20 | 30 | 6 | 6 | 17 |
| Professional | 24 | 23 | 19 | 15 | 15 |
| Professional | 25 | 28 | 17 | 18 | 17 |
| Professional | 15 | 16 | 12 | 3 | 18 |
| Counseling | 20 | 19 | 20 | 16 | 24 |
| Redistribution | 40 | 36 | 12 | 8 | 20 |
| Counseling | 28 | 18 | 24 | 17 | 18 |
| Counseling | 28 | 20 | 32 | 8 | 12 | 
| Redistribution | 25 | 27 | 15 | 17 | 22 |
| Redistribution | 24 | 36 | 20 | 16 | 4 |
| Redistribution | 23 | 22 | 29 | 18 | 24 |
| Counseling | 20 | 28 | 24 | 8 | 24 |
| Counseling | 30 | 28 | 22 | 21 | 20 |
| Counseling | 38 | 12 | 22 | 4 | 31 |
| Counseling | 20 | 12 | 24 | 8 | 12 |
| Counseling | 30 | 24 | 24 | 20 | 29 |
| Counseling | 24 | 32 | 19 | 13 | 32 |
| All services | 35 | 34 | 17 | 14 | 14 |
| All services | 25 | 29 | 31 | 23 | 16 |
| All services | 36 | 33 | 28 | 18 | 18 |
| All services | 33 | 36 | 20 | 13 | 7 |
| All services | 27 | 21 | 26 | 17 | 26 |
+ ------------------- + ------------------ + ---------- -------- + ------------------ + ------------------ + --- --------------- +.

Answer 1

In general, it turned out like this. I do not know how true it is

df = pd.read_excel ('DataFrame throughout the sphere, placed .xlsx', sheet_name = 'all', index_col = 0)
For col in df.columns:
  Plt.figure (Figsize = (16, 8))
  x = df.index
  Y = DF [COL]
  PLT.SUBPLOTS_ADJUST (Bottom = 0.25, Top = 0.79)
  AX = SNS.BOXPLOT (X, Y)
  Plt.xticks (Rotation = 80)
  Plt.Show ()

Answer 2

I can not understand what you need and that it does not go out, but it is the BOXPLOT on the columns of the DATAPHREAM to build a lot easier:

df = pd.dataframe (np.random.randn (20, 3),
         columns = ['Cl1', 'Cl2', 'Cl3'])
DF.BoxPlot (column = ['Cl1', 'Cl2', 'Cl3'])

And if on rows – then like this:

df ['sphere'] = pd.series (['a', 'a', 'a', 'A', 'A',
           'B', 'b', 'b', 'b', 'b',
           'C', 'c', 'b', 'b', 'd',
           'D', 'D', 'A', 'B', 'C'])
BoxPlot = df.Boxplot (column = ['cl1', 'cl2', 'cl3'], by = 'sphere')

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions