Infer Objects
Sat 17 May 2025
title: "Infer Objects" author: "Rj" date: 2019-04-24 description: "-" type: technical_note draft: false
import numpy as np
import pandas as pd
df = pd.DataFrame({'a': [7, 1, 5], 'b': ['3','2','1']}, dtype='object')
df
| a | b | |
|---|---|---|
| 0 | 7 | 3 |
| 1 | 1 | 2 |
| 2 | 5 | 1 |
df.dtypes
a object
b object
dtype: object
df = df.infer_objects()
df.dtypes
a int64
b object
dtype: object
# You can see that dataype of column a is changed to int64.
Score: 5
Category: data-wrangling