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 need to pass a collection of index values as parameter while appending to the given <code>index</code> object.</p>

<pre><code>indx.append(pd.Index([20]))   # Pass the values inside the list 
Int64Index([11, 12, 13, 14, 15, 20], dtype='int64')
</code></pre>

python pandas