1

If I do the following:

In [1]: import pandas as pd

In [2]: series1 = pd.Series([0, 5, 2, 3])

In [3]: series1
Out[3]: 
0    0
1    5
2    2
3    3
dtype: int64

In [4]: series2 = pd.Series([2, 3, 1])

In [5]: series2
Out[5]: 
0    2
1    3
2    1
dtype: int64

Then when I add series 1 and 2 together, I get a NaN at the third row.

In [6]: series1 + series2
Out[6]: 
0     2
1     8
2     3
3   NaN
dtype: float64

Without modifying the index of series 2, is it possible to have the summation be:

In [6]: series1 + series2
Out[6]: 
0     2
1     8
2     3
3     3
dtype: float64

such that the value of index 3 in series 1 is preserved after summation?

ericmjl
  • 13,541
  • 12
  • 51
  • 80
  • So the NaN should be replaced with the value immediately above it? – Ffisegydd Aug 13 '14 at 20:23
  • Ah, sorry for the confusion. No, it should not be replaced with the value immediately above it. I would like to ignore the fact that index 3 is absent in series2, and simply preserve the value of index 3 in series 1 in the sum. I will modify the question to be clearer. – ericmjl Aug 13 '14 at 20:24
  • Actually, I think I found the answer to my question: http://stackoverflow.com/questions/11106823/adding-two-pandas-dataframes – ericmjl Aug 13 '14 at 20:27

0 Answers0