如何将熊猫系列与DataFrame合并

问题描述 投票:0回答:1

我创建了一个没有列名称的pd.Series,看起来像这样:

Data Inicial                          2019-12-02
Data Final                            2019-12-06
Rentabilidade do Período                 0.2863%
CDI Acumulado no Período                    4.9%
Rentabilidade Relativa                   5.8419%
Evolução do Patrimônio              -0.000454579
Menor Retorno Diário        2019-12-06: (-0.24%)
Maior Retorno Diário         2019-12-05: (0.25%)
dtype: object

我有一个DataFrame看起来像这样:

Data  Ganhos Acumulados
1944 2019-12-02           0.000000
1945 2019-12-03           0.189677
1946 2019-12-04          -0.155147
1947 2019-12-05           0.248015
1948 2019-12-06          -0.236190

我需要:我需要用两个数据结构创建一个DataFrame,因为在此之后,我将其转换为HTML并在前端进行打印。

新的DataFrame应该看起来像这样:

Data Inicial                          2019-12-02
Data Final                            2019-12-06
Rentabilidade do Período                 0.2863%
CDI Acumulado no Período                    4.9%
Rentabilidade Relativa                   5.8419%
Evolução do Patrimônio              -0.000454579
Menor Retorno Diário        2019-12-06: (-0.24%)
Maior Retorno Diário         2019-12-05: (0.25%)
2019-12-02                              0.000000
2019-12-03                              0.189677
2019-12-04                             -0.155147
2019-12-05                              0.248015
2019-12-06                             -0.236190

我该怎么办?

python-3.x pandas dataframe series
1个回答
0
投票

假设s是您的Seriesdf是您的DataFrame

s=s.append(df.set_index('Ganhos')['Acumulados'])
© www.soinside.com 2019 - 2024. All rights reserved.