【发布时间】:2019-04-16 11:51:10
【问题描述】:
我有我的字典
d = {'A':1, 'B':2, 'C':3}
和我的数据框
df =pd.DataFrame({
"col1": ["A", "B", "C"],
"col2": [1, 2, 3],
"col3": [2, 1, 4] })
我搜索将 df 中的每个值与字典中的对应值进行比较。如果匹配,则保留该值,否则丢弃该值。
我试试
m = df['col2'] >= d[df['col1']]
df.where(m, df, other = "")
但它得到了 m 的错误代码:TypeError: 'Series' objects are mutable, 因此它们不能被散列......
感谢您的帮助。
【问题讨论】:
-
发布你的错误
-
TypeError: 'Series' 对象是可变的,因此它们不能被散列
-
是的。应用应该解决这个问题
标签: python pandas dictionary dataframe indexing