Skip to content
Advertisement

How to convert each values in Data Frame to int and float in only one index row in Python Pandas?

I have Pandas Data Frame in Python like below:

JavaScript

IDX is and index of this Data Frame. And I would like to add new row in this Data Frame which will calculate mathematic formula like:

JavaScript

So for example: (250 - 120) / 250 = 0.52 So as a result I need something like below:

JavaScript

because:

JavaScript

I used code like below:

JavaScript

Nevertheless, after using above code (which works) values in my DF changed from int to float and looks like below:

JavaScript

What can I do so as to acheive DF like below?????:

JavaScript

Advertisement

Answer

There are same types of each column in pandas by default, so close is multiple and divide, but still there are floats columns:

JavaScript

Possible solution is transpose – original integers are not changed and new column is filled by floats:

JavaScript

Another idea with formaters g:

JavaScript

Or converting to strings:

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