taotao.li
taotao.li

Reputation: 1082

pandas pivot dataframe structure

raw data

enter image description here

pivot table enter image description here

question

how can I replace industryName with tradeDate and remove that blank row? I want to make it look like:

the screenshot below is created by IPython-Dashboard

enter image description here

Upvotes: 1

Views: 153

Answers (2)

Happy001
Happy001

Reputation: 6383

You can reset_index to convert you index to a regular column.

data_pivot.reset_index()

Upvotes: 1

Alexander
Alexander

Reputation: 109528

tradeDate is the name of your index. You can remove it via:

data_pivot.index.name = None

industryName is the name of your columns. You can change that be equal to tradeDate via:

data_pivot.columns.name = 'tradeDate'

Upvotes: 1

Related Questions