Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to fill the empty cell above index title in Pandas?

I know that I can use df.index.name() to put a title on my index and it will return the index name in a new row, something like:

        column1    column2
index
  0       foo        bar

And I already did it, but I still need to save the timestamp on that df, and for organization purposes, I would like to put it in the "apparently empty" cell above the index, something like:

timestamp    column1    column2
  index
    0          foo        bar

Is there a way to make it work? I’m looking through pandas docs but so far I found nothing…
Thanks in advance!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

No, there is no way in pandas.
But what’s wrong with df.index.name = 'timestamp'?, giving you

          column1 column2
timestamp
0             foo     bar

If it’s just about how the printed data frame looks like, you could do the following:

df.index.name = 'index'
print('timestamp', repr(df)[6:])
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading