Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
fix spelling, grammar, no need to put your username at the end
Source Link
Tonechas
  • 13.8k
  • 16
  • 52
  • 85

I have this DataframeDataframe:

import pandas as pd df = pd.DataFrame({'Hugo' : {'age' : 21, 'weight' : 75}, 'Bertram': {'age' : 45, 'weight' : 65}, 'Donald' : {'age' : 75, 'weight' : 85}}).T df.index.names = ['name'] age weight name Bertram 45 65 Donald 75 85 Hugo 21 75 

I want to change the index to the column 'age''age':

df.set_index('age', inplace=True) weight age 45 65 75 85 21 75 

The old index-column name gets lost. Is there a way to change the index without losing the original index-column and getting the old column alsas 'normal' column again, so that it looks like this:?

 name weight age 45 Bertram 65 75 Donald 85 21 Hugo 75 

Thanks

I have this Dataframe:

import pandas as pd df = pd.DataFrame({'Hugo' : {'age' : 21, 'weight' : 75}, 'Bertram': {'age' : 45, 'weight' : 65}, 'Donald' : {'age' : 75, 'weight' : 85}}).T df.index.names = ['name'] age weight name Bertram 45 65 Donald 75 85 Hugo 21 75 

I want to change the index to the column 'age':

df.set_index('age', inplace=True) weight age 45 65 75 85 21 75 

The old index-column name gets lost. Is there a way to change the index without losing the original index-column and getting the old column als 'normal' column again, so that it looks like this:

 name weight age 45 Bertram 65 75 Donald 85 21 Hugo 75 

Thanks

I have this Dataframe:

import pandas as pd df = pd.DataFrame({'Hugo' : {'age' : 21, 'weight' : 75}, 'Bertram': {'age' : 45, 'weight' : 65}, 'Donald' : {'age' : 75, 'weight' : 85}}).T df.index.names = ['name'] age weight name Bertram 45 65 Donald 75 85 Hugo 21 75 

I want to change the index to the column 'age':

df.set_index('age', inplace=True) weight age 45 65 75 85 21 75 

The old index-column name gets lost. Is there a way to change the index without losing the original index-column and getting the old column as 'normal' column again, so that it looks like this?

 name weight age 45 Bertram 65 75 Donald 85 21 Hugo 75 
fix spelling, grammar, no need to put your username at the end
Source Link

I have this Dataframe:

import pandas as pd df = pd.DataFrame({'Hugo' : {'age' : 21, 'weight' : 75}, 'Bertram': {'age' : 45, 'weight' : 65}, 'Donald' : {'age' : 75, 'weight' : 85}}).T df.index.names = ['name'] age weight name Bertram 45 65 Donald 75 85 Hugo 21 75 

now iI want to change the index to the column 'age':

df.set_index('age', inplace=True) weight age 45 65 75 85 21 75 

now theThe old index-column name gets lost. Is there a way to change the index without loosinglosing the oldoriginal index-column and getting the old column als 'normal' column again, so that it should looklooks like this ?:

 name weight age 45 Bertram 65 75 Donald 85 21 Hugo 75 

Thanks

Egirus

I have this Dataframe:

import pandas as pd df = pd.DataFrame({'Hugo' : {'age' : 21, 'weight' : 75}, 'Bertram': {'age' : 45, 'weight' : 65}, 'Donald' : {'age' : 75, 'weight' : 85}}).T df.index.names = ['name'] age weight name Bertram 45 65 Donald 75 85 Hugo 21 75 

now i want to change the index to the column 'age'

df.set_index('age', inplace=True) weight age 45 65 75 85 21 75 

now the old index-column name gets lost. Is there a way to change the index without loosing the old index-column and getting the old column als 'normal' column again, so it should look like this ?

 name weight age 45 Bertram 65 75 Donald 85 21 Hugo 75 

Thanks

Egirus

I have this Dataframe:

import pandas as pd df = pd.DataFrame({'Hugo' : {'age' : 21, 'weight' : 75}, 'Bertram': {'age' : 45, 'weight' : 65}, 'Donald' : {'age' : 75, 'weight' : 85}}).T df.index.names = ['name'] age weight name Bertram 45 65 Donald 75 85 Hugo 21 75 

I want to change the index to the column 'age':

df.set_index('age', inplace=True) weight age 45 65 75 85 21 75 

The old index-column name gets lost. Is there a way to change the index without losing the original index-column and getting the old column als 'normal' column again, so that it looks like this:

 name weight age 45 Bertram 65 75 Donald 85 21 Hugo 75 

Thanks

edited tags
Link
Aran-Fey
  • 44k
  • 13
  • 113
  • 161
Source Link
Egirus Ornila
  • 1.3k
  • 4
  • 17
  • 42
Loading