I can't plot the boxplot for Gender and Age. Anybody know why?
Sample of dataframe
1 |
df.boxplot(by = 'Gender' , column = [ 'Age' ]) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - TypeError Traceback (most recent call last) <ipython - input - 34 - 6c670e351f01 > in <module> 1 #boxplot = df.boxplot(column=['Age']) 2 - - - - > 3 boxplot = df.boxplot(by = 'Gender' , column = [ 'Age' ]) 4 boxplot ~\anaconda3\lib\site - packages\pandas\plotting\_core.py in boxplot_frame( self , column, by, ax, fontsize, rot, grid, figsize, layout, return_type, backend, * * kwargs) 434 ): 435 plot_backend = _get_plot_backend(backend) - - > 436 return plot_backend.boxplot_frame( 437 self , 438 column = column, ~\anaconda3\lib\site - packages\pandas\plotting\_matplotlib\boxplot.py in boxplot_frame( self , column, by, ax, fontsize, rot, grid, figsize, layout, return_type, * * kwds) 362 import matplotlib.pyplot as plt 363 - - > 364 ax = boxplot( 365 self , 366 column = column, ~\anaconda3\lib\site - packages\pandas\plotting\_matplotlib\boxplot.py in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, * * kwds) 314 # Prefer array return type for 2-D plots to match the subplot layout - - > 316 result = _grouped_plot_by_column( 317 plot_group, 318 data, ~\anaconda3\lib\site - packages\pandas\plotting\_matplotlib\boxplot.py in _grouped_plot_by_column(plotf, data, columns, by, numeric_only, grid, figsize, ax, layout, return_type, * * kwargs) 204 gp_col = grouped[col] 205 keys, values = zip ( * gp_col) - - > 206 re_plotf = plotf(keys, values, ax, * * kwargs) 207 ax.set_title(col) 208 ax.set_xlabel(pprint_thing(by)) ~\anaconda3\lib\site - packages\pandas\plotting\_matplotlib\boxplot.py in plot_group(keys, values, ax) 285 keys = [pprint_thing(x) for x in keys] 286 values = [np.asarray(remove_na_arraylike(v)) for v in values] - - > 287 bp = ax.boxplot(values, * * kwds) 288 if fontsize is not None : 289 ax.tick_params(axis = "both" , labelsize = fontsize) ~\anaconda3\lib\site - packages\matplotlib\cbook\deprecation.py in wrapper( * args, * * kwargs) 294 f "for the old name will be dropped %(removal)s." ) 295 kwargs[new] = kwargs.pop(old) - - > 296 return func( * args, * * kwargs) 297 298 # wrapper() must keep the same documented signature as func(): if we ~\anaconda3\lib\site - packages\matplotlib\__init__.py in inner(ax, data, * args, * * kwargs) 1563 def inner(ax, * args, data = None , * * kwargs): 1564 if data is None : - > 1565 return func(ax, * map (sanitize_sequence, args), * * kwargs) 1566 1567 bound = new_sig.bind(ax, * args, * * kwargs) ~\anaconda3\lib\site - packages\matplotlib\axes\_axes.py in boxplot( self , x, notch, sym, vert, whis, positions, widths, patch_artist, bootstrap, usermedians, conf_intervals, meanline, showmeans, showcaps, showbox, showfliers, boxprops, labels, flierprops, medianprops, meanprops, capprops, whiskerprops, manage_ticks, autorange, zorder) 3625 bootstrap = rcParams[ 'boxplot.bootstrap' ] 3626 - > 3627 bxpstats = cbook.boxplot_stats(x, whis = whis, bootstrap = bootstrap, 3628 labels = labels, autorange = autorange) 3629 if notch is None : ~\anaconda3\lib\site - packages\matplotlib\cbook\__init__.py in boxplot_stats(X, whis, bootstrap, labels, autorange) 1203 1204 # arithmetic mean - > 1205 stats[ 'mean' ] = np.mean(x) 1206 1207 # medians and quartiles <__array_function__ internals> in mean( * args, * * kwargs) ~\anaconda3\lib\site - packages\numpy\core\fromnumeric.py in mean(a, axis, dtype, out, keepdims) 3332 return mean(axis = axis, dtype = dtype, out = out, * * kwargs) 3333 - > 3334 return _methods._mean(a, axis = axis, dtype = dtype, 3335 out = out, * * kwargs) 3336 ~\anaconda3\lib\site - packages\numpy\core\_methods.py in _mean(a, axis, dtype, out, keepdims) 161 ret = ret.dtype. type (ret / rcount) 162 else : - - > 163 ret = ret / rcount 164 165 return ret TypeError: unsupported operand type (s) for / : 'str' and 'int' |
1 2 3 4 5 6 |
Product Branch Age Gender Education MaritalStatus Usage Fitness Income Miles 0 M1 West 18 Male 14 Single na 4 29562 112 1 M1 East 19 Male 15 Single 2 3 31836 75 2 M1 West 19 Female 14 Partnered 4 3 30699 66 3 M1 South na na na na na na na na 4 M1 West 19 Male 12 Single na 3 32973 85 |