1

I have a dataframe like this:

    ip        name
 0  10.1.1.1  aa
 1  10.1.1.2  bb

I want to remove index column and set ip for index:

ip         name
10.1.1.1   aa
10.1.1.2   bb

reset_index() and df.index.name not working...

11
  • 2
    df.set_index('ip') - has been answered before. Commented Oct 12, 2017 at 9:36
  • need df = df.set_index('ip') Commented Oct 12, 2017 at 9:36
  • set_index('ip') not working . Because print df.index.name is None and df still has a third column Commented Oct 12, 2017 at 9:40
  • 1
    Assumming the dataframe is df, you can use df.reset_index(drop=True, inplace=True) df = df.set_index('ip') Commented Oct 12, 2017 at 9:44
  • @akilat90 could you please write as answer for accepting this? Commented Oct 12, 2017 at 9:44

1 Answer 1

3

Set desired and drop current:

df.set_index('ip', drop=True)

As it was pointed out in one of the comments, to make changes inplace you can use either:

df.set_index('ip', drop=True, inplace=True)

or

df = df.set_index('ip', drop=True)
Sign up to request clarification or add additional context in comments.

1 Comment

set_index('ip') not working . Because print df.index.name is None and df still has a third column

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.