How to Split Explode Pandas DataFrame String Entry to Separate Rows Last Updated : 27 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report When working with Pandas, you may encounter columns with multiple values separated by a delimiter. To split these strings into separate rows, you can use the split() and explode() functions.str.split() splits the string into a list of substrings based on a delimiter (e.g., space, comma).explode() transforms the list into separate rows, where each list item gets its own row.Let's learn how to split and explode Pandas DataFrame entry to separate rows.Splitting Strings into Columns Let's say we have a DataFrame with a column of strings containing comma-separated names. We can split these strings into separate columns as follows: Python import pandas as pd data = {'Names': ['Alice,Bob,Charlie', 'David,Eve', 'Frank']} df = pd.DataFrame(data) # Splitting the string column into separate columns df[['Name1', 'Name2', 'Name3']] = df['Names'].str.split(',', expand=True) print(df) Output: Names Name1 Name2 Name30 Alice,Bob,Charlie Alice Bob Charlie1 David,Eve David Eve None2 Frank Frank None NoneExploding the Split Columns into Separate RowsOnce you've split the strings, you may want to explode these split values into individual rows. Here's how you can use explode() to achieve this: Python # Exploding the 'Names' column df_exploded = df['Names'].str.split(',').explode().reset_index(drop=True) print(df_exploded) Output: 0 Alice1 Bob2 Charlie3 David4 Eve5 FrankName: Names, dtype: objectSplitting and Exploding in Pandas DataFrame is useful for cleaning survey data where multiple answers are stored in one field. This allows you to analyze individual responses more easily, such as counting how many times a specific hobby appears across all respondents. Comment More infoAdvertise with us Next Article Split a String into columns using regex in pandas DataFrame S singhrohinish09 Follow Improve Article Tags : Pandas Python-pandas Geeks Premier League 2023 Similar Reads How to preprocess string data within a Pandas DataFrame? Sometimes, the data which we're working on might be stuffed in a single column, but for us to work on the data, the data should be spread out into different columns and the columns must be of different data types. When all the data is combined in a single string, the string needs to be preprocessed. 3 min read How To Break Up A Comma Separated String In Pandas Column Working with datasets often involves scenarios where multiple items are stored in a single column as a comma-separated string. Let's learn how to break up a comma-separated string in the Pandas Column. Using str.split()Weâll use a simple dataset where a column contains categories and their respectiv 3 min read Split a String into columns using regex in pandas DataFrame Given some mixed data containing multiple values as a string, let's see how can we divide the strings using regex and make multiple columns in Pandas DataFrame. Method #1: In this method we will use re.search(pattern, string, flags=0). Here pattern refers to the pattern that we want to search. It ta 3 min read Pandas - DataFrame to CSV file using tab separator Let's see how to convert a DataFrame to a CSV file using the tab separator. We will be using the to_csv() method to save a DataFrame as a csv file. To save the DataFrame with tab separators, we have to pass "\t" as the sep parameter in the to_csv() method. Approach :Â Import the Pandas and Numpy mod 1 min read How to write Pandas DataFrame as TSV using Python? In this article, we will discuss how to write pandas dataframe as TSV using Python. Let's start by creating a data frame. It can be done by importing an existing file, but for simplicity, we will create our own. Python3 # importing the module import pandas as pd # creating some sample data sample = 1 min read How to Get substring from a column in PySpark Dataframe ? In this article, we are going to see how to get the substring from the PySpark Dataframe column and how to create the new column and put the substring in that newly created column. We can get the substring of the column using substring() and substr() function. Syntax: substring(str,pos,len) df.col_n 3 min read Like