• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Unable to convert pandas str column with .0 to int

Resolved: Unable to convert pandas str column with .0 to int

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

Let’s say I have a dataframe that looks like this…
foo
1
2
3

And I want to convert the column to type int. I can do that easily with…
But if my dataframe looks like this…
foo
1.0
2.0
3.0

And I try to convert it from object to int then I get this error
Why doesn’t this work? How would I go about converting this to an int properly?

Answer:

Just do a two step conversion, string to float then float to int.
It works with or without the decimal point.

If you have better answer, please add a comment about this, thank you!

pandas python-3.x
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Best way to create 3d matrix of variables in PULP

24/03/2023

Resolved: Openlayers: Update clusters depending on filter (geometryFunction)

24/03/2023

Resolved: Getting ‘502 Bad Gateway’ while deploying Springboot app in EKS

24/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.