Conversion Methods

Learn how to perform data type conversions on a Series.

Sometimes we’ll need to change the type of the data. This might be due to formats that don’t include type information, or it might be that we can have better performance (more manipulation options or less memory usage) by changing types.

Automatic conversion

In pandas 1.0, a new conversion method was introduced, namely convert_dtypes. This tries to convert a Series to a type that supports pd.NA. In the case of our city_mpg Series, it will change the type from int64 to Int64 like this:

Get hands-on with 1400+ tech skills courses.