1

i have a dataframe with the data as follows

  id  Name   Age     
0  1  XXX    30 

and i have to remove the 0(the row index value) from the dataframe.

I have tried the folowing

df.reset_index(inplace=True) # Resets the index, makes factor a column
df.drop("Factor",axis=1,inplace=True)  

but it is not removing the 0.

i want output like:

id  Name   Age     
 1  XXX    30 
7
  • 1
    Do you need this ? Commented Feb 18, 2020 at 8:12
  • Do you want to save csv file without index? Commented Feb 18, 2020 at 8:15
  • it is not possible to display something like that however you can take output into csv. Commented Feb 18, 2020 at 8:16
  • @jezrael i tried but it is not removing the index value. Commented Feb 18, 2020 at 8:17
  • 1
    dataframe without index can not exist. You can make id as index, by using set_index() function. While saving to file (csv etc), you can make index = False. Commented Feb 18, 2020 at 8:31

3 Answers 3

1

Try this one:

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

Comments

0

You can use the pandas function set_index

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

Comments

0

In Pandas index is not a separate column that you can remove. It's an indicator like the indicator in array and dictionary.

For example if you have:

letters = ["a", "b", "c", "d", "e"]
letters[2]

2 is an indicator that cannot be removed from array.

But depending your use of dataframe you can tell pandas not to show index in the export.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.