【问题标题】:Python Pandas: Add values to another columnPython Pandas:将值添加到另一列
【发布时间】:2021-06-25 07:56:13
【问题描述】:
Col1 Col2
10 10
15 25
05 30
33 63

如何从给定的 Col1 生成 Col2

【问题讨论】:

  • 你能详细说明你想要什么吗?你有 Col1 并且你想创建 Col2?你想要什么逻辑?

标签: python pandas row add


【解决方案1】:

你可以使用cumsum:

df['Col2'] = df['Col1'].cumsum()
df

输出:

   Col1  Col2
0    10    10
1    15    25
2     5    30
3    33    63

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-13
    • 2017-03-07
    • 2022-06-11
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 2021-03-23
    • 1970-01-01
    相关资源
    最近更新 更多