gpt4 book ai didi

python - 如何在现有数据框中创建具有独立行值的列

转载 作者:行者123 更新时间:2023-12-01 08:41:54 25 4
gpt4 key购买 nike

我在 pandas DataFrame 中有一个像这样的数据框,其中 A 是列名称:

results.head()
A
when you are away
when I was away
when they are away

我想添加一个新的 B 列,如下所示:

A                   B
when you are away you
when I was away I
when they are away they

我尝试使用此代码,但它不起作用:

results.assign(B = you, I, they)

我是 pandas dataframe 的新手,非常感谢您的帮助。

最佳答案

试试这个:

B_list = ['you','I','they']
results['B'] = B_list

或者

results = results.assign(B=['you', 'I', 'they'])

关于python - 如何在现有数据框中创建具有独立行值的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53466107/

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