pandas.DataFrame.infer_objects — pandas 3.0.0.dev0+2095.g2e141aaf99 documentation (original) (raw)

DataFrame.infer_objects(copy=<no_default>)[source]#

Attempt to infer better dtypes for object columns.

Attempts soft conversion of object-dtyped columns, leaving non-object and unconvertible columns unchanged. The inference rules are the same as during normal Series/DataFrame construction.

Parameters:

copybool, default False

Whether to make a copy for non-object or non-inferable columns or Series.

Note

The copy 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 and ignore the copy keyword. The copy keyword will be removed in a future version of pandas.

You can already get the future behavior and improvements through enabling copy on write pd.options.mode.copy_on_write = True

Deprecated since version 3.0.0.

Returns:

same type as input object

Returns an object of the same type as the input object.

Examples

df = pd.DataFrame({"A": ["a", 1, 2, 3]}) df = df.iloc[1:] df A 1 1 2 2 3 3

df.dtypes A object dtype: object

df.infer_objects().dtypes A int64 dtype: object