String Manipulation

Learn how to manipulate strings in a Series.

String data is commonly used to hold free-form text, semi-structured text, categorical data, and data that should have another type (typically numeric or datetime). Let’s look at common operations of textual data.

Strings and objects

Before pandas 1.0, if we stored strings in a Series, the underlying type of the Series would be an object. This is undesirable as the object type can be used for other Series that have Python types in them (such as a list, a dictionary, or a custom class). Also, the object type is used for mixed types. If we have a Series that has numbers and strings in it, the type is also object.

In pandas 1.0, the new string type was introduced. In addition to being more explicit than object, it supports missing values that are not NaN.

The “make” column has an object type by default:

Get hands-on with 1400+ tech skills courses.