Pandas index column title or name

How do I get the index column name in python pandas? Here's an example dataframe:

                 Column 1
    Index Title          
    Apples              1
    Oranges             2
    Puppies             3
    Ducks               4

What I'm trying to do is get/set the dataframe index title. Here is what i tried:

    import pandas as pd
    data = {'Column 1'     : [1., 2., 3., 4.],
            'Index Title'  : ["Apples", "Oranges", "Puppies", "Ducks"]}
    df = pd.DataFrame(data)
    df.index = df["Index Title"]
    del df["Index Title"]
    print df

Anyone know how to do this?

You can just get/set the index via its name property

    In [7]:
    Out[7]: 'Index Title'

    In [8]: = 'foo'

    In [9]:
    Out[9]: 'foo'

    In [10]: df
             Column 1
    Apples          1
    Oranges         2
    Puppies         3
    Ducks           4


Back to homepage or read more recommendations: