Pandas 替换为loc将引发无效的类型比较

Pandas 替换为loc将引发无效的类型比较,pandas,Pandas,替换为loc引发类型错误无效类型比较。在excel中,两列都是文本。这里出了什么错 d= {'col1': ['Very High', 'High'], 'col2': ['High', 'Very High]} LL = pd.DataFrame(data=d) LL.loc[LL['col1'] == 'Very High', 'col1'] = 4 #Error LL.loc[LL['col2'] == 'Very High', 'col2'] = 4 #No error col

替换为loc引发类型错误无效类型比较。在excel中,两列都是文本。这里出了什么错

d= {'col1': ['Very High', 'High'], 'col2': ['High', 'Very High]}
LL = pd.DataFrame(data=d)

LL.loc[LL['col1'] == 'Very High', 'col1'] = 4  #Error
LL.loc[LL['col2'] == 'Very High', 'col2'] = 4   #No error

col1                                  object
col2                                  object


C:\Program Files (x86)\Anaconda3\lib\site-packages\pandas\core\ops.py:1164: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  result = method(y)

TypeError: invalid type comparison

您能否提供一个示例数据集,以便我们能够实际查看导致错误的内容?它从excel中读取数据,它是两列文本形式。见上文。谢谢。这对我来说不会产生错误。您使用的是什么版本的pandas?如果值是字符串,col1的数据类型如何为
int64