Skip to content
Advertisement

Mutiplying dataframe by -1 loses data

I have an issue and I have no idea what is causing it.. I have a very very simply dataframe which looks like the following;

JavaScript

I simply need to convert this dataframe to positive numbers. When I do this with a simple;

JavaScript

A column multiples but the B column loses its’ data to the following;

JavaScript

I assume this is something to do with interger vs float64 but just can’t crack it.

Any help much appreciated!

Advertisement

Answer

You likely have strings in your data, multiplying a string by an integer less than 1 converts to empty string:

JavaScript

output:

JavaScript

Workaround: convert to_numeric:

JavaScript

output:

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