【发布时间】:2015-09-15 04:05:12
【问题描述】:
我有一个 pandas 数据框和一个一维的 numpy nd 数组。实际上它是一个列表。
如何使用数组中的值向 DataFrame 添加新列?
test['preds'] = preds 给SettingWithCopyWarning
还有一个警告:
试图在 DataFrame 的切片副本上设置一个值。 尝试改用 .loc[row_indexer,col_indexer] = value
当我尝试pd.DataFrame({test,preds}) 我得到TypeError: unhashable type: 'list'
【问题讨论】:
-
你原来的df是什么?如果
test已经是一个df,那么test['preds']=preds就可以了。 -
要回答
SettingWithCopyWarning,您需要发布您的原始DataFrame
标签: python arrays numpy pandas