- API reference
- DataFrame
- pandas.DataF...
pandas.DataFrame.infer_objects#
- DataFrame.infer_objects(copy=None)[source]#
Attempt to infer better dtypes for object columns.
Attempts soft conversion of object-dtypedcolumns, leaving non-object and unconvertiblecolumns unchanged. The inference rules are thesame as during normal Series/DataFrame construction.
- Parameters:
- copybool, default True
Whether to make a copy for non-object or non-inferable columnsor Series.
Note
Thecopy keyword will change behavior in pandas 3.0.Copy-on-Writewill be enabled by default, which means that all methods with acopy keyword will use a lazy copy mechanism to defer the copy andignore thecopy keyword. Thecopy keyword will be removed in afuture version of pandas.
You can already get the future behavior and improvements throughenabling copy on write
pd.options.mode.copy_on_write=True
- Returns:
- same type as input object
See also
to_datetime
Convert argument to datetime.
to_timedelta
Convert argument to timedelta.
to_numeric
Convert argument to numeric type.
convert_dtypes
Convert argument to best possible dtype.
Examples
>>>df=pd.DataFrame({"A":["a",1,2,3]})>>>df=df.iloc[1:]>>>df A1 12 23 3
>>>df.dtypesA objectdtype: object
>>>df.infer_objects().dtypesA int64dtype: object