question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

simple barplot with orient='v' - unsupported operand type(s) for /: 'str' and 'long'

See original GitHub issue

Same error as closed issue https://github.com/mwaskom/seaborn/issues/578? Recording incase #578 won’t apply to barplots. Code as follows. Replacing orient=‘h’ works.

import pandas as pd
import seaborn as sns

plt.close('all')
zeros=90
nonzeros=10
df = pd.DataFrame({'zeros':[zeros], 'total':[zeros+nonzeros], 'label':['Zero']})
sns.set(font_scale=1, style='white')
sns.set_color_codes('pastel')
sns.barplot(x="total", y="label", data=df, orient='v',  label="Zero", color="b")

sns.set_color_codes('muted')
ax = sns.barplot(x="zeros", y="label", data=df, orient='v', label="Non-zero", color="b")

plt.show()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-30-ba4f2d6ec1da> in <module>()
      8 sns.set(font_scale=1, style='white')
      9 sns.set_color_codes('pastel')
---> 10 sns.barplot(x="total", y="label", data=df, orient='v',  label="Zero", color="b")
     11 
     12 sns.set_color_codes('muted')

c:\Anaconda2\lib\site-packages\seaborn\categorical.pyc in barplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, errwidth, capsize, ax, **kwargs)
   2897                           estimator, ci, n_boot, units,
   2898                           orient, color, palette, saturation,
-> 2899                           errcolor, errwidth, capsize)
   2900 
   2901     if ax is None:

c:\Anaconda2\lib\site-packages\seaborn\categorical.pyc in __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, orient, color, palette, saturation, errcolor, errwidth, capsize)
   1543                                  order, hue_order, units)
   1544         self.establish_colors(color, palette, saturation)
-> 1545         self.estimate_statistic(estimator, ci, n_boot)
   1546 
   1547         self.errcolor = errcolor

c:\Anaconda2\lib\site-packages\seaborn\categorical.pyc in estimate_statistic(self, estimator, ci, n_boot)
   1438                     statistic.append(np.nan)
   1439                 else:
-> 1440                     statistic.append(estimator(stat_data))
   1441 
   1442                 # Get a confidence interval for this estimate

c:\Anaconda2\lib\site-packages\numpy\core\fromnumeric.pyc in mean(a, axis, dtype, out, keepdims)
   2940 
   2941     return _methods._mean(a, axis=axis, dtype=dtype,
-> 2942                             out=out, **kwargs)
   2943 
   2944 

c:\Anaconda2\lib\site-packages\numpy\core\_methods.pyc in _mean(a, axis, dtype, out, keepdims)
     70         ret = ret.dtype.type(ret / rcount)
     71     else:
---> 72         ret = ret / rcount
     73 
     74     return ret

TypeError: unsupported operand type(s) for /: 'str' and 'long'

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Aug 17, 2016

If your y variable is categorical you can’t draw a vertical barplot.

0reactions
mmagnuskicommented, Aug 18, 2016

On a side note:

sr = pd.Series([1, 2, 3, np.nan], dtype=object)
pd.to_numeric(sr, errors='ignore').dtype

works, but probably not in all reasonable cases. So +1 on not doing any checks 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Seaborn boxplot: TypeError: unsupported operand type(s) for
For seaborn's boxplots it is important to keep an eye on the x-axis and y-axis assignments, when switching between horizontal and vertical ...
Read more >
Bar Plots - Quick-R
Create simple and stacked barplots in R with the barplot(height) function, where height is a vector or matrix.
Read more >
Seaborn barplot color - miocittadino.it
Write a Python program to create bar plot from a DataFrame. ... type(s) for /: 'str' and 'long' simple barplot with orient='v' -...
Read more >
Create Scatter, Line and Bar Charts using Matplotlib
How to Create a Bar Chart using Matplotlib. Bar charts are used to display categorical data. Here is an example of a dataset...
Read more >
seaborn.barplot — seaborn 0.12.1 documentation - PyData |
Show point estimates and errors as rectangular bars. A bar plot represents an estimate of central tendency for a numeric variable with the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found