-
-
Notifications
You must be signed in to change notification settings - Fork 19.3k
Closed
Labels
BugClosing CandidateMay be closeable, needs more eyeballsMay be closeable, needs more eyeballsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversions
Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
df = pd.DataFrame({"col1": ["123", "456"], "col2": ["1.23", "45.6"]})
>>> df.dtypes
# col1 object
# col2 object
# dtype: object
>>> df.convert_dtypes().dtypes
# col1 string[python]
# col2 string[python]
# dtype: object
>>> df.infer_objects().dtypes
# col1 object
# col2 object
# dtype: objectIssue Description
As stated in the title, neither of the two methods succeeds in correctly inferring the best possible dtypes.
Expected Behavior
A possible workaround would be :
>>> df.apply(pd.to_numeric).dtypes
# col1 int64
# col2 float64
# dtype: object
Installed Versions
Replace this line with the output of pd.show_versions()
Metadata
Metadata
Assignees
Labels
BugClosing CandidateMay be closeable, needs more eyeballsMay be closeable, needs more eyeballsDtype ConversionsUnexpected or buggy dtype conversionsUnexpected or buggy dtype conversions