How to get dataframe index from series?
<p>Say I extract a series from a dataframe (like what would happen with an apply function). I'm trying to find the original dataframe index from that series.</p>

<pre><code>df=pd.DataFrame({'a':[1,2,3],'b':[4,5,6],'c':[7,8,9]})
x=df.ix[0]
x


Out[109]: 
a    1
b    4
c    7
Name: 0, dtype: int64
</code></pre>

<p>Notice the "Name: 0" piece at the bottom of the output. How can I get the value '0' from series object x?</p>

<p>you access it with the <code>name</code> attribute</p>

<pre><code>x.name

0
</code></pre>

<p>take these examples</p>

<pre><code>for i, row in df.iterrows():
    print row.name, i

0 0
1 1
2 2
</code></pre>

<p>Notice that the name attribute is the same as the variable <code>i</code> which is supposed to be the row index.</p>

<p>It's the same for columns</p>

<pre><code>for j, col in df.iteritems():
    print col.name, j

a a
b b
c c
</code></pre>

python pandas indexing dataframe series