【发布时间】:2017-01-28 16:02:55
【问题描述】:
我想为我使用 for 循环的数据框中添加每条记录的概率
def map_score(dataframe,customers,prob):
dataframe['Propensity'] = 0
for i in range(len(dataframe)):
for j in range(len(customers)):
if dataframe['Client'].iloc[i] == customers[j]:
dataframe["Propensity"].iloc[i] = prob[j]
我能够正确映射与每个客户端关联的概率,但 Python 会抛出警告消息
试图在 DataFrame 的切片副本上设置一个值。 尝试改用 .loc[row_indexer,col_indexer] = value
请参阅文档中的注意事项:http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy 从 ipykernel 导入 kernelapp 作为应用程序
当我使用 .loc 函数时,结果是错误的,我得到的是空值。 请提出一个有条件地更新和添加条目的好方法
【问题讨论】:
标签: python loops pandas dataframe