2016-05-10 6 views
-2

Kaggle Титаника с помощью питона 2,7Ошибка: неподдерживаемый тип операнда (ов) для /: 'ул' и 'длинным'

import pandas as pd 
from pandas import Series,DataFrame 

titanic_df = pd.read_csv("train.csv") 

import numpy as np 
import seaborn as sns 
import matplotlib.pyplot as plt 
%matplotlib inline 

**sns.factorplot('Pclass',data=titanic_df,hue='Sex')** 

Получение ошибки Ниже

TypeError         Traceback (most recent call last) 
<ipython-input-7-a5240a4b6a9f> in <module>() 
     1 # Let's first check gender 
----> 2 sns.factorplot('Sex',data=titanic_df) 

C:\Users\bigminduser\Anaconda2\lib\site-packages\seaborn-0.7.0-py2.7.egg\seaborn\categorical.pyc in factorplot(x, y, hue, data, row, col, col_wrap, estimator, ci, n_boot, units, order, hue_order, row_order, col_order, kind, size, aspect, orient, color, palette, legend, legend_out, sharex, sharey, margin_titles, facet_kws, **kwargs) 
    3365 
    3366  # Draw the plot onto the facets 
-> 3367  g.map_dataframe(plot_func, x, y, hue, **plot_kws) 
    3368 
    3369  # Special case axis labels for a count type plot 

C:\Users\bigminduser\Anaconda2\lib\site-packages\seaborn-0.7.0-py2.7.egg\seaborn\axisgrid.pyc in map_dataframe(self, func, *args, **kwargs) 
    791 
    792    # Draw the plot 
--> 793    self._facet_plot(func, ax, args, kwargs) 
    794 
    795   # Finalize the annotations and layout 

C:\Users\bigminduser\Anaconda2\lib\site-packages\seaborn-0.7.0-py2.7.egg\seaborn\axisgrid.pyc in _facet_plot(self, func, ax, plot_args, plot_kwargs) 
    809 
    810   # Draw the plot 
--> 811   func(*plot_args, **plot_kwargs) 
    812 
    813   # Sort out the supporting information 

C:\Users\bigminduser\Anaconda2\lib\site-packages\seaborn-0.7.0-py2.7.egg\seaborn\categorical.pyc in pointplot(x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, orient, color, palette, ax, **kwargs) 
    3009        estimator, ci, n_boot, units, 
    3010        markers, linestyles, dodge, join, scale, 
-> 3011        orient, color, palette) 
    3012 
    3013  if ax is None: 

C:\Users\bigminduser\Anaconda2\lib\site-packages\seaborn-0.7.0-py2.7.egg\seaborn\categorical.pyc in __init__(self, x, y, hue, data, order, hue_order, estimator, ci, n_boot, units, markers, linestyles, dodge, join, scale, orient, color, palette) 
    1575         order, hue_order, units) 
    1576   self.establish_colors(color, palette, 1) 
-> 1577   self.estimate_statistic(estimator, ci, n_boot) 
    1578 
    1579   # Override the default palette for single-color plots 

C:\Users\bigminduser\Anaconda2\lib\site-packages\seaborn-0.7.0-py2.7.egg\seaborn\categorical.pyc in estimate_statistic(self, estimator, ci, n_boot) 
    1434      statistic.append(np.nan) 
    1435     else: 
-> 1436      statistic.append(estimator(stat_data)) 
    1437 
    1438     # Get a confidence interval for this estimate 

C:\Users\bigminduser\Anaconda2\lib\site-packages\numpy\core\fromnumeric.pyc in mean(a, axis, dtype, out, keepdims) 
    2872 
    2873  return _methods._mean(a, axis=axis, dtype=dtype, 
-> 2874       out=out, keepdims=keepdims) 
    2875 
    2876 

C:\Users\bigminduser\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'** 

ответ

1

Эй У меня был такой же точный вопрос! Я нашел ответ, связанный здесь:

Issue with seaborn in sublime

Надеется, что это работает для вас!

1

Основано на ответе @batmac. Добавив kind="count" к команде, она решила проблему.

Пример:

import pandas as pd 
import seaborn as sns 

data = pd.read_csv('train.csv') 
sns.factorplot('Sex', data=data, kind="count")