neuniversity / ALY6140

1 stars 3 forks source link

Reset the index #35

Open ShailuKonda opened 5 years ago

ShailuKonda commented 5 years ago

I used a column as an index. I want to remove the column as an index. I used df.reset_index(). It didnt work. Is there any other way i can remove the index .

ThatkidfromA commented 5 years ago

Hello, I hope this will help your problem, did you include level of columns in the argument? For example data.reset_index(level=['A'], inplace = True). Level will select the column.

I hope the link below will help. https://github.com/pandas-dev/pandas/issues/16263

ZelingJiang commented 5 years ago

I had the same problem when I use groupby function. The command I used is 'as_index = False'. It will add a new index instead of using the first column as an index.

NEUHU commented 5 years ago

Try "reset_index", see if that helps. If not, you can take a look on the link below:https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset_index.html Or check the code you put in, sometimes anything that is slightly different or a typo may cause the failure, too.

xyz04 commented 5 years ago

I found some code maybe have the function that you need. Delete row index rearrange: ser.reset_index(drop = True) df.reset_index(drop = True)

Modify the column index directly: df = pd.DataFrame(df,columns = ['One','Two','Three'])

Hope that will help you.

CHENGYULIU1 commented 5 years ago

I think you should use reset_index(). In this case, you might miss some parameters. Do check the documentation if you haven't gotten the answer!

pr24 commented 5 years ago

S.reset_index(inplace=True,drop=True)