2016-11-18 81 views
0

我有一個DataFrame稱爲products,它有這樣的結構和數據:如何將列轉換爲與索引具有相同現有值的索引?

Products

我想知道我怎麼轉換Product ID指數與相同值的列,併成爲DataFrame指數。

我已經試過

products = products.reset_index() 

,這是我得到了什麼:

new products DataFrame

我想要得到的是:

New DataFrame with the required index

+1

你不能有一個'DataFrame'沒有索引......所以,當你使用'.reset_index()'使得索引中的列 - 它把一個默認指數。這會對你造成什麼困難?例如:產品ID作爲索引/或作爲列,但具有默認索引時出了什麼問題? –

回答

0

您可以使用這用於獲得期望的結果:

products = products.set_index('Product ID') 

enter image description here

+0

它不起作用! – InfZero

+0

它適用於我。我附上了截圖供參考。 – Nain

相關問題