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 
userD1989
  • 47
  • 1
  • 7

3 Answers3

1

Try this one:

df.set_index('id', inplace=True)
Nurul Akter Towhid
  • 3,046
  • 2
  • 33
  • 35
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.

Nurul Akter Towhid
  • 3,046
  • 2
  • 33
  • 35
0

You can use the pandas function set_index

df.set_index('id', inplace=True, drop=True)
N. P.
  • 503
  • 4
  • 12