gpt4 book ai didi

python - 将列表作为列添加到数据框的正确方法是什么?

转载 作者:行者123 更新时间:2023-12-04 04:05:20 26 4
gpt4 key购买 nike

我想将列表作为新列添加到数据框中。我正在做:

df['Intervention'] = interventionList

它给了我

SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame

我读了Pandas add a series to dataframe column接受的答案非常相似。

最佳答案

我相信一种选择是使用:

df.assign(Intervention = interventionList)

或制作数据框的副本:

df2 = df.copy()

关于python - 将列表作为列添加到数据框的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62599732/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com