2015-04-21 11 views
22

mam dataframe jak ten:Usuń nazwę indeksu w pand

In [10]: df 
Out[10]: 
     Column 1 
foo    
Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 

Jak usunąć index namefoo z tego dataframe? Pożądana moc jest tak:

In [10]: df 
Out[10]: 
     Column 1    
Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 

Odpowiedz

21

Zastosowanie del df.index.name

In [16]: df 
Out[16]: 
     Column 1 
foo 
Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 

In [17]: del df.index.name 

In [18]: df 
Out[18]: 
     Column 1 
Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 
16

Alternatywnie można po prostu przypisać None do atrybutu index.name:

In [125]: 

df.index.name = None 
df 
Out[125]: 
     Column 1 

Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 
+2

Lepiej przypisać "Brak" do tego. – joris

+0

Tak, to byłoby semantycznie poprawne, zaktualizuje – EdChum

13

Od wersji 0.18.0 można wykorzystać rename_axis:

print df 
     Column 1 
foo    
Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 

print df.index.name 
foo 


print df.rename_axis(None) 
     Column 1 
Apples   1 
Oranges   2 
Puppies   3 
Ducks   4 

print df.rename_axis(None).index.name 
None 
Powiązane problemy