我想尝试的是,如果满足df配置,则将x值添加到变量中
范例
local_bid = 0
df.loc[["Entity"] == "Keyword"]
那么
local_bid = df["Bid"]
我试过了
df.loc[["Entity"] == "Keyword", local_bid] = df["Bid"]
但没有成功
Traceback (most recent call last):
File "/home/shaumne/Desktop/zorba/Sp_limpr.py", line 17, in <module>
s =limpr.loc[["Entity"] == "Keyword", local_bid] = limpr["Bid"]
File "/home/shaumne/.local/lib/python3.10/site-packages/pandas/core/indexing.py", line 818, in __setitem__
iloc._setitem_with_indexer(indexer, value, self.name)
File "/home/shaumne/.local/lib/python3.10/site-packages/pandas/core/indexing.py", line 1703, in _setitem_with_indexer
key, _ = convert_missing_indexer(idx)
File "/home/shaumne/.local/lib/python3.10/site-packages/pandas/core/indexing.py", line 2585, in convert_missing_indexer
raise KeyError("cannot use a single bool to index into setitem")
KeyError: 'cannot use a single bool to index into setitem'
1条答案
按热度按时间qlfbtfca1#
您需要比较列
df["Entity"]
,而不是列出["Entity"]
: