请前辈指点下
比如a=[1.2.3.4]
生成的要[1.3.6.10]
比如a=[1.2.3.4]
生成的要[1.3.6.10]
|
GavinFlyingSep 15, 2016
1
如果是 Pandas :
```python num_list = [1, 2, 3, 4] df = pd.DataFrame(data=num_list) df.cumsum() ``` 如果不用 Pandas: ```python num_list = [1, 2, 3, 4] [sum(num_list[:idx]) for idx in range(1, len(num_list) + 1)] ``` |
|
2
谢谢,前辈,第一个是我想要的,非常感谢啊,我原来还想 reduce 什么的
|
|
3
@GavinFlying
谢谢,第一个是我想要的,非常感谢啊,我原来还想 reduce 什么的 |
|
4
@GavinFlying 可以再问你个 pandas 问题吗?生成累加列,因为之前 groupby 过,如何还原回去。就是要与 groupby 之前的数据结构一致
|
|
5
@GavinFlying 我想到的笨办法是把 groupby 的结果用 pd.concat 接合起来
|
|
GavinFlyingSep 15, 2016
6
@sylvos Sorry, 并不懂...感觉应该要自己实现
|
|
dgkaeSep 15, 2016
7
厉害哦
|
|
imn1Sep 15, 2016
8
这些类似的逐行计算的,属于移动统计范畴,你需要看 pandas 手册, computational tools 这一章
|