Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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 numpy选择类型错误:不可损坏类型:“列表-numpy需要列表”_Python_Pandas_Numpy - Fatal编程技术网

Python numpy选择类型错误:不可损坏类型:“列表-numpy需要列表”

Python numpy选择类型错误:不可损坏类型:“列表-numpy需要列表”,python,pandas,numpy,Python,Pandas,Numpy,我试图使用数据帧中一列的值生成一个新列,如stackoverflow文章所示: 当我尝试运行以下代码时: conditions = [ newData['month'] == 1, newData['month'] == 2, newData['month'] == 3, newData['month'] == 4, newData['month'] == 5, newData['month'] == 6, newData['month']

我试图使用数据帧中一列的值生成一个新列,如stackoverflow文章所示:

当我尝试运行以下代码时:

conditions = [
    newData['month'] == 1,
    newData['month'] == 2,
    newData['month'] == 3,
    newData['month'] == 4,
    newData['month'] == 5,
    newData['month'] == 6,
    newData['month'] == 7,
    newData['month'] == 8,
    newData['month'] == 9,
    newData['month'] == 10,
    newData['month'] == 11,
    newData['month'] == 12]
output = [1,1,1,2,2,2,3,3,3,4,4,4]
newData['quarter'] = newData.select(conditions, output)
我得到了错误类型error:unhabable类型:“list”

我知道列表是不可散列的,但是numpy需要两个参数都有列表

从文件中:

condlist:list of bool ndarrays确定从choicelist中的哪个数组获取输出元素的条件列表。当满足多个条件时,将使用condlist中遇到的第一个条件

condlist:list of bool ndarrays确定从choicelist中的哪个数组获取输出元素的条件列表。当满足多个条件时,将使用condlist中遇到的第一个条件

我不知道问题出在哪里使用:

newData['quarter'] = (newData['month'].sub(1) // 3).add(1)
如果没有重复月份,且已订购:

newData['quarter'] =  newData['month'].mod(3).eq(1).cumsum().add(1)
您的问题是您需要np.select

使用:

如果没有重复月份,且已订购:

newData['quarter'] =  newData['month'].mod(3).eq(1).cumsum().add(1)
您的问题是您需要np.select


啊,我知道我会错过一些基本的东西。非常感谢。啊,我知道我会错过一些基本的东西。非常感谢。