gpt4 book ai didi

python - 类型错误 : Cannot do inplace boolean setting on mixed-types with a non np. nan 值

转载 作者:太空狗 更新时间:2023-10-29 20:57:56 43 4
gpt4 key购买 nike

当我尝试用特定字符串值替换多列中的数值时,出现错误 TypeError: Cannot do inplace boolean setting on mixed-types with a non np.nan value

df =

TYPE VD_1 VD_2 VD_3
AAA 1234 22122 2345
AAA 1234 2345 22122

我是这样做的:

df[df.isin([22122])] = "English"

df[df==22122] = "English"

最佳答案

如果您堆叠 df,那么您可以将整个 df 与标量值进行比较,替换然后取消堆叠:

In [122]:
stack = df.stack()
stack[ stack == 22122] = 'English'
stack.unstack()

Out[122]:
TYPE VD_1 VD_2 VD_3
0 AAA 1234 English 2345
1 AAA 1234 2345 English

替换:

In [125]:
df.replace(22122,'English', inplace=True)
df

Out[125]:
TYPE VD_1 VD_2 VD_3
0 AAA 1234 English 2345
1 AAA 1234 2345 English

关于python - 类型错误 : Cannot do inplace boolean setting on mixed-types with a non np. nan 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42276396/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com