【发布时间】:2018-11-30 20:29:05
【问题描述】:
import matplotlib as plt
%matplotlib inline
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import seaborn as sns
df.head()
Out[46]:
PassengerId Survived Pclass ... Fare Cabin Embarked
0 1 0 3 ... 7.2500 NaN S
1 2 1 1 ... 71.2833 C85 C
2 3 1 3 ... 7.9250 NaN S
3 4 1 1 ... 53.1000 C123 S
4 5 0 3 ... 8.0500 NaN S
[5 rows x 12 columns]
df = pd.read_csv('D:\dframe.csv')
sns.factorplot('Sex', data = df)
错误:
Traceback (most recent call last):
File "<ipython-input-45-703be846d61b>", line 1, in <module>
sns.factorplot('Sex', data = df)
File "C:\ProgramData\Anaconda3\lib\site-packages\seaborn\categorical.py", line 3530, in factorplot
g.map_dataframe(plot_func, x, y, hue, **plot_kws)
File "C:\ProgramData\Anaconda3\lib\site-packages\seaborn\axisgrid.py", line 809, in map_dataframe
self._facet_plot(func, ax, args, kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\seaborn\axisgrid.py", line 827, in _facet_plot
func(*plot_args, **plot_kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\seaborn\categorical.py", line 3143, in pointplot
orient, color, palette, errwidth, capsize)
File "C:\ProgramData\Anaconda3\lib\site-packages\seaborn\categorical.py", line 1669, in __init__
self.estimate_statistic(estimator, ci, n_boot)
File "C:\ProgramData\Anaconda3\lib\site-packages\seaborn\categorical.py", line 1482, in estimate_statistic
statistic.append(estimator(stat_data))
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\fromnumeric.py", line 2957, in mean
out=out, **kwargs)
File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\_methods.py", line 82, in _mean
ret = ret / rcount
TypeError: unsupported operand type(s) for /: 'str' and 'int'
我使用的数据集是一个 csv 文件“train.csv”:
【问题讨论】:
-
你能给我们看看 df.head() 的输出吗
-
@tobsecret df.head() Out[46]:PassengerId Survived Pclass ... 票价客舱登机 0 1 0 3 ... 7.2500 NaN S 1 2 1 1 ... 71.2833 C85 C 2 3 1 3 ... 7.9250 NaN S 3 4 1 1 ... 53.1000 C123 S 4 5 0 3 ... 8.0500 NaN S [5 行 x 12 列]
-
@DevenBothra 你能把它格式化放在问题中吗。不在 cmets 中。
标签: python python-3.x pandas numpy