Python Pandas str.split() Method Syntax

Syntax: Series.str.split(pat=None, n=-1, expand=False)

Parameters: 

  • pat: String value, separator or delimiter to separate string at. 
  • n: Numbers of max separations to make in a single string, default is -1 which means all. 
  • expand: Boolean value, returns a data frame with different value in different columns if True. Else it returns a series with list of strings. 

Return Type: Series of list or Data frame depending on expand Parameter

Sample DataFrame

To download the CSV used in the code, click here. In the following examples, the data frame used contains data of some NBA players. The image of data frame before any operations is attached below. 

Python | Pandas Split strings into two List/Columns using str.split()

Pandas provide a method to split string around a passed separator/delimiter. After that, the string can be stored as a list in a series or it can also be used to create multiple column data frames from a single separated string. It works similarly to Python’s default split() method but it can only be applied to an individual string. Pandas <code>str.split() method can be applied to a whole series. .str has to be prefixed every time before calling this method to differentiate it from Python’s default function otherwise, it will throw an error. To work in google colab import the files before using the dataset.

In this article, we will learn about how we can split strings into two columns using str.split()

Similar Reads

Python Pandas str.split() Method Syntax

Syntax: Series.str.split(pat=None, n=-1, expand=False) Parameters:  pat: String value, separator or delimiter to separate string at.  n: Numbers of max separations to make in a single string, default is -1 which means all.  expand: Boolean value, returns a data frame with different value in different columns if True. Else it returns a series with list of strings.  Return Type: Series of list or Data frame depending on expand Parameter...

Split Strings in Pandas

Splitting String into List...

Contact Us