Reputation: 689
After doing some calculation, I ended up with a data frame full of such values '(312+0j)'
. Complex numbers but strings. How can I convert them back to real numbers? I have no complex numbers at all, due to some calculations in np.eignval
it add the +0j
. I am thinking of doing a regex but wanted to know if there is a faster and easier way to accomplish this.
Upvotes: 1
Views: 315
Reputation: 150775
You can convert it to complex:
complex('(312+0j)').real
# 312.0
Upvotes: 4