Add a value to the end of a pandas index object
<p>I have a pandas index object and I'd like to add a single value to the end of it. The .append() method doesn't seem to work like one would expect, and since I'm trying to add an element, I can't insert at the location of -1 because that puts the value in the second-to-last position. For example</p>

<pre><code>import pandas as pd
ser = pd.Series([1,2,3,4,5], index=[11,12,13,14,15])
indx = ser.index
</code></pre>

<p>Say I want to add the value 20 to the end of the index. This throws an error:</p>

<pre><code>indx.append(20)
</code></pre>

<p>This returns [11,12,13,14,20,15]:</p>

<pre><code>indx.insert(-1, 20)
</code></pre>

<p>This works but seems like a work-around:</p>

<pre><code>indx.insert(len(indx), 20)
</code></pre>

<p>Is there something I'm missing? This is on pandas 0.18.1. Thanks.</p>

<p>You may want to try these two options:</p>

<pre><code>import pandas as pd
import numpy as np
ser.append(pd.Series([np.nan], index = [20]))

# 11    1.0
# 12    2.0
# 13    3.0
# 14    4.0
# 15    5.0
# 20    NaN
# dtype: float64

ser.set_value(20, np.nan)

# 11    1.0
# 12    2.0
# 13    3.0
# 14    4.0
# 15    5.0
# 20    NaN
# dtype: float64
</code></pre>

python pandas