如何在列表中添加多个 pandas 数据系列的项目-python [英] How to add items of multiple panda dataseries in a list - python
本文介绍了如何在列表中添加多个 pandas 数据系列的项目-python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个列表 final_value,其中包含熊猫系列以及下面的数据。我需要将多个熊猫系列的战利品添加到一个系列中。
谁能帮助我。
I am having a list 'final_value' which contains panda series with data below. I need to add the vales of multiple panda series into one series. Can anyone please help me.
需要根据其索引值添加值。
Need to add values according to their index value.
我在循环中尝试了 final_value [i] .add(final_value [i + 1])
。
数据:
[0 0.000000
1 14.522873
2 21.677418
3 10.791055
4 0.000000
5 7.176507
Name: (FDIUSGD Index, PX_LAST), Length: 6, dtype: float64,
0 -16.276548
1 -16.276548
2 -15.761264
3 -16.276548
4 -16.276548
5 -17.822402
Name: (USHBMIDX Index, PX_LAST), Length: 6, dtype: float64,
0 0.000000
1 5.972322
2 15.255200
3 -3.498313
4 2.698414
5 3.083199
Name: (USPHNSA Index, PX_LAST), Length: 6, dtype: float64,
期望输出:
0 -16.276548
1 4.218647
2 21.171354
3 -8.983806
4 -13.578134
5 -7.562696
谢谢!
推荐答案
在 axis = 1 $ c $上使用
pd.concat
c>和 sum
行e
Use pd.concat
on axis=1
and sum
row-wise
In [597]: pd.concat(final_value, axis=1).sum(axis=1)
Out[597]:
0 -16.276548
1 4.218647
2 21.171354
3 -8.983806
4 -13.578134
5 -7.562703
dtype: float64
详细信息
In [598]: final_value
Out[598]:
[0 0.000000
1 14.522873
2 21.677418
3 10.791055
4 0.000000
5 7.176500
Name: 1, dtype: float64, 0 -16.276548
1 -16.276548
2 -15.761264
3 -16.276548
4 -16.276548
5 -17.822402
Name: 1, dtype: float64, 0 0.000000
1 5.972322
2 15.255200
3 -3.498313
4 2.698414
5 3.083199
Name: 1, dtype: float64]
这篇关于如何在列表中添加多个 pandas 数据系列的项目-python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文