2024-03-28 11:03:13 发布
网友
在np.where(cond,A,B)中,Python计算cond、A和B,然后将它们传递给where函数。where然后broadcasts将输入彼此相对,并执行按元素选择。您似乎有3个嵌套的where。我猜错误发生在最里面的一个,因为它将首先被评估(我不必猜测您是否提供了错误回溯。)
np.where(cond,A,B)
cond
A
B
where
broadcasts
np.where( # When hash codes are available and matched. 3.2 'Y' ( ~df['new_hash'].isna() & ~df['old_hash'].isna() & df['new_hash'].ne(df['old_hash']) ), ['Y', df['cr_date'], current_time], ['N', df['cr_date'], df['up_date']] )
cond部分是第一个()逻辑和表达式。你知道吗
()
A是3元素列表,B是下一个列表。你知道吗
假设有66行,cond将具有(66,)形状。你知道吗
np.array(['Y', df['cr_date'], current_time])可能是一个(3,)形对象数据类型数组,因为输入包含在字符串、序列和时间对象上。你知道吗
np.array(['Y', df['cr_date'], current_time])
这说明了错误消息中的3个形状:shapes (66,) (3,) (3,))
shapes (66,) (3,) (3,))
如果一次只设置一列,表达式将是np.where(cond, 'Y', 'N')或np.where(cond, Series1, Series2)。你知道吗
np.where(cond, 'Y', 'N')
np.where(cond, Series1, Series2)
如果您不明白我(或错误)所说的broadcasting是什么意思,您可能需要进一步了解numpy(它是pandas的基础)。你知道吗
broadcasting
numpy
pandas
在
np.where(cond,A,B)
中,Python计算cond
、A
和B
,然后将它们传递给where
函数。where
然后broadcasts
将输入彼此相对,并执行按元素选择。您似乎有3个嵌套的where
。我猜错误发生在最里面的一个,因为它将首先被评估(我不必猜测您是否提供了错误回溯。)cond
部分是第一个()
逻辑和表达式。你知道吗A
是3元素列表,B
是下一个列表。你知道吗假设有66行,
cond
将具有(66,)形状。你知道吗np.array(['Y', df['cr_date'], current_time])
可能是一个(3,)形对象数据类型数组,因为输入包含在字符串、序列和时间对象上。你知道吗这说明了错误消息中的3个形状:
shapes (66,) (3,) (3,))
如果一次只设置一列,表达式将是
np.where(cond, 'Y', 'N')
或np.where(cond, Series1, Series2)
。你知道吗如果您不明白我(或错误)所说的
broadcasting
是什么意思,您可能需要进一步了解numpy
(它是pandas
的基础)。你知道吗相关问题 更多 >
编程相关推荐