Skip to content
Advertisement

How do I name the dataframe index after a variable result?

I have a variable called ‘Specimen’ from a dataframe imported from a xlsx file, and I want to implement the result of this variable (in this case 25) in a new dataframe?

What I have:

JavaScript

array([[25.0]], dtype=object)

JavaScript
JavaScript

What I want:

JavaScript

I have tried

JavaScript

But this gives the following error: TypeError: RangeIndex.name must be a hashable type

ps: I’m quite new here, so I hope I’m asking thing the right way, Many thanks in advance

Advertisement

Answer

I feel like I may be missing a requirement from your question but here is what I think might work for you:

Set the variable to match yours:

JavaScript

Then rename the index:

JavaScript

The index has been renamed:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement