Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Countplot函数不适用于装箱数据_Python_Pandas_Seaborn_Data Science - Fatal编程技术网

Python Countplot函数不适用于装箱数据

Python Countplot函数不适用于装箱数据,python,pandas,seaborn,data-science,Python,Pandas,Seaborn,Data Science,因此,我一直在尝试将数据分发到存储箱中,然后在其上使用countplot函数。但这给了我一个错误。代码的装箱部分似乎工作正常,问题可能在于countplot函数。如果你能建议如何纠正以下问题,那就太好了。 ps:这可能看起来很琐碎,但我对数据科学还不熟悉 binned=pd.cut(lab3['Survived'],[0,10,20,30,40,50,60,70,80]) p = sns.countplot(x='Survived',data=binned, hue='Survived') 错

因此,我一直在尝试将数据分发到存储箱中,然后在其上使用countplot函数。但这给了我一个错误。代码的装箱部分似乎工作正常,问题可能在于countplot函数。如果你能建议如何纠正以下问题,那就太好了。 ps:这可能看起来很琐碎,但我对数据科学还不熟悉

binned=pd.cut(lab3['Survived'],[0,10,20,30,40,50,60,70,80])
p = sns.countplot(x='Survived',data=binned, hue='Survived')
错误:

ValueError                                Traceback (most recent call last)
<ipython-input-41-67a29c8aa363> in <module>()
      1 labels = [0-10,11-20]
      2 binned=pd.cut(lab3['Survived'],[0,10,20,30,40,50,60,70,80])
----> 3 p = sns.countplot(x='Survived',data=binned, hue='Survived')

3 frames
/usr/local/lib/python3.6/dist-packages/seaborn/categorical.py in establish_variables(self, x, y, hue, data, orient, order, hue_order, units)
    151                 if isinstance(var, str):
    152                     err = "Could not interpret input '{}'".format(var)
--> 153                     raise ValueError(err)
    154 
    155             # Figure out the plotting orientation

ValueError: Could not interpret input 'Survived'
ValueError回溯(最近一次调用)
在()
1标签=[0-10,11-20]
2 binned=局部切割(lab3[‘存活’],[0,10,20,30,40,50,60,70,80])
---->3 p=sns.countplot(x='surved',data=bined,hue='surved')
3帧
/usr/local/lib/python3.6/dist-packages/seaborn/categorical.py中的建立变量(self、x、y、色调、数据、方向、顺序、色调顺序、单位)
151如果存在(变量、str):
152 err=“无法解释输入“{}”。格式(var)
-->153提升值错误(err)
154
155#算出绘图方向
ValueError:无法解释输入“幸存”
pd.cut()
返回一个
系列
对象(并且不返回带有新列的原始
数据帧
。因此,如果您打印
binned
,它会尝试打印
系列
,但找不到原始列

您可以将装箱系列添加到原始数据帧:

lab3.assign(binned=pd.cut(lab3['Survived'],[0,10,20,30,40,50,60,70,80]))
我想以后策划工作会如期进行