我刚刚用 cudf (rapidsai) 加载了 csv 文件以减少所需的时间。当我尝试使用 where 条件搜索索引时出现问题 df['X'] = A
。
这是我的代码示例:
import cudf, io, requests
df = cudf.read_csv('fileA.csv')
# X is an existing column
# A is the value
df['X'] = np.where(df['X'] == A, 1, 0)
# What it is supposed to do with pandas is it search the index where df['X'] is equal to value A,
# and change them to 1, otherwise leave them as 0.
但是,错误显示如下:
if len(cond) ! = len(self):
raise ValueError("""Array conditional must be same shape as self""")
input_col = self._data[self.name]
ValueError : Array conditional must be same shape as self
我不明白为什么会这样,因为我以前从来没有遇到过熊猫的任何问题。