Splitting
In some cases, strings contain several pieces of information so we might need to split a string in order to access one piece of information.
In staff
, the name
column contains both the first and last names. We can easily extract the first or last names from the name
column by using the split
function.
The Pandas split
function is available under the str
accessor. It splits a string at the position of the given character and then returns a list of all parts.
Let’s look at a simple example first. The following code snippet splits the name
column at the space character.
Get hands-on with 1400+ tech skills courses.