You can do:

df["Shape"]=df["Shape"].str.split("\r\n")
print(df.explode("Shape").reset_index(drop=True))

Output:

   Color    Shape   Price
0   Green   Rectangle   10
1   Green   Triangle    10
2   Green   Octangle    10
3   Blue    Rectangle   15
4   Blue    Triangle    15
Answer from Sociopath on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › split-pandas-dataframe-by-rows
Split Pandas Dataframe by Rows - GeeksforGeeks
July 15, 2025 - In this article, we will elucidate several commonly employed methods for Split Pandas Dataframe by Rows.
Discussions

Pandas to split single df row into multiple
You're being too fancy and it's messing you up. Given: >>> df ID Name1 Age Name2 Age2 0 001 Joe 25 Mary 89.0 1 002 Chris 38 NaN NaN Just make IDs the index, separate out the two sets of Name + Age columns, rename their columns to be the same, then concatenate and drop NA rows. >>> df = df.set_index('ID') >>> df1 = df.iloc[:, :2] >>> df2 = df.iloc[:, 2:] >>> df2.columns = df1.columns >>> df = pd.concat([df1, df2]).dropna().sort_index().reset_index() Produces: >>> df ID Name1 Age 0 001 Joe 25.0 1 001 Mary 89.0 2 002 Chris 38.0 More on reddit.com
🌐 r/learnpython
3
2
March 25, 2022
Split the pandas dataframe by a column value
Hi I have about 20 big pandas pandas data frame, each with 100,000 rows like this a b 1 0.3 1 0.5 ...... 2 3.4 ...... 2 0.4 ...... 1000 0.3 1000 4.5 where a = 1 for the first 100 rows, a = 2 for the second 100 rows, etc. Now I want to divide the dataframes into smaller ones, I tried N = 1000 ... More on discuss.python.org
🌐 discuss.python.org
1
0
March 21, 2023
ENH: Add split method to DataFrame for flexible row-based partitioning
Currently, pandas does not provide a direct, built-in method to split a DataFrame into multiple smaller DataFrames based on a number of specified rows. Users seeking to partition a DataFrame into chunks either have to relay on workarounds using loops and manual indexing. More on github.com
🌐 github.com
5
March 20, 2024
python - Pandas Split DataFrame using row index - Stack Overflow
1 Splitting a dataframe by passing a list of indices · 92 Split pandas dataframe based on values in a column using groupby · 1 Split each row into multiple groups using Pandas groupby? More on stackoverflow.com
🌐 stackoverflow.com
November 21, 2018
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › how to split pandas dataframe?
How to Split Pandas DataFrame? - Spark By {Examples}
December 6, 2024 - You can split the Pandas DataFrame based on rows or columns by using Pandas.DataFrame.iloc[] attribute, groupby().get_group(), sample() functions. It
🌐
Reddit
reddit.com › r/learnpython › pandas to split single df row into multiple
r/learnpython on Reddit: Pandas to split single df row into multiple
March 25, 2022 -

Hi there. I'm trying to rack my brain about how to accomplish this. I have a form where each submission is one row in a csv file.

ID Name1 Age Name2 Age
001 Joe 25 Mary 89
002 Chris 38

What I want to accomplish is to splice a single row into 2 rows if Name2 has a value. I want to take this original df, and create something like this:

ID Name Age
001 Joe 25
001 Mary 89
002 Chris 38

That way, I can still group submissions (it's easy to see that Joe and Mary came from the same form), but I have a clean df.

df2=pd.DataFrame(columns=['ID','Name','Age])

#append just the first 3 columns 0,1,2 to new df2
for x in range(len(df):
   df2.append(df[x,0:3]

   #append columns 0,3,4  to df2--but only if there is data in the Name2 column
   if pd.notnull(df.iloc[x,3]):
      df2.append(df.iloc[x,0]   
      df2.append(df.iloc[x,3:5]

This is my logic, but not implementing correctly. Can somebody point me to the right direction? Is this a smart way to approach this? In reality, I have a csv file with about 100 columns and I'm picking and choosing new columns to be added to a much cleaner second data frame. This involves lots of guessing about which columns I want and then getting the right index for .iloc.

Thanks for any tips.

🌐
datagy
datagy.io › home › pandas tutorials › pandas dataframes › python: split a pandas dataframe
Python: Split a Pandas Dataframe • datagy
December 16, 2022 - Let’s say we wanted to split a Pandas dataframe in half. We would split row-wise at the mid-point. The way that we can find the midpoint of a dataframe is by finding the dataframe’s length and dividing it by two.
🌐
Delft Stack
delftstack.com › home › howto › python pandas › split pandas dataframe
How to Split Pandas DataFrame | Delft Stack
February 2, 2024 - We can specify the rows to be included in each split in the iloc property. [:2,:] represents select the rows up to row with index 2 exclusive (the row with index 2 is not included) and all the columns from the DataFrame.
Find elsewhere
🌐
GitHub
gist.github.com › jlln › 338b4b0b55bd6984f883
Efficiently split Pandas Dataframe cells containing lists into multiple rows, duplicating the other column's values. · GitHub
def split_data_frame_list(df, target_column): """ Splits a column with lists into rows Keyword arguments: df -- dataframe target_column -- name of column that contains lists """ # create a new dataframe with each item in a seperate column, dropping rows with missing values col_df = pd.DataFrame(df[target_column].dropna().tolist(),index=df[target_column].dropna().index) # create a series with columns stacked as rows stacked = col_df.stack() # rename last column to 'idx' index = stacked.index.rename(names="idx", level=-1) new_df = pd.DataFrame(stacked, index=index, columns=[target_column]) return new_df
🌐
Finxter
blog.finxter.com › 5-best-ways-to-split-a-pandas-dataframe-row-into-multiple-rows
5 Best Ways to Split a Pandas DataFrame Row Into Multiple Rows – Be on the Right Side of Change
February 19, 2024 - The apply() method along with pd.Series() can be used when you need to split a DataFrame’s rows based on a column containing strings that need to be separated into multiple elements. This combination is useful for customized splitting operations. ... import pandas as pd # Sample DataFrame ...
🌐
GitHub
github.com › pandas-dev › pandas › issues › 57934
ENH: Add split method to DataFrame for flexible row-based partitioning · Issue #57934 · pandas-dev/pandas
March 20, 2024 - def split_dataframe(df, n, remainder=None): 1.) Get total number of rows in the dataframe 2.) Check for divisibility of remainder is None: 2.1) If length is not perfectly divisible by n, raise an error.
Author   pandas-dev
🌐
Statology
statology.org › home › how to split a pandas dataframe into multiple dataframes
How to Split a Pandas DataFrame into Multiple DataFrames
August 5, 2021 - by Zach Bobbitt Published on Published on August 5, 2021 · You can use the following basic syntax to split a pandas DataFrame into multiple DataFrames based on row number:
🌐
Java2Blog
java2blog.com › home › python › pandas › split dataframe in pandas
Split dataframe in Pandas - Java2Blog
July 28, 2021 - We can select the required range of rows from the DataFrame using the iloc() function. See the following example. ... In the above example, we split the DataFrame based on rows.
🌐
GeeksforGeeks
geeksforgeeks.org › split-pandas-dataframe-by-column-value
Split Pandas Dataframe by column value - GeeksforGeeks
April 20, 2022 - A distributed collection of data grouped into named columns is known as a Pyspark data frame in Python. There occurs various circumstances in which you need only particular rows in the data frame. For this, you need to split the data frame according to the column value. This can be achieved either ... Pandas support two data structures for storing data the series (single column) and dataframe where values are stored in a 2D table (rows and columns).
🌐
DataScientYst
datascientyst.com › how-to-split-dataframe-in-pandas
How to split dataframe in Pandas
September 4, 2023 - Let's see all the steps in details ... columns=list('ABCD')) data looks like: Numpy method np.array_split() can be used on Pandas DataFrame to split it in n chunks: import pandas as pd import numpy as np df = pd.DataFrame(n...
🌐
Untitled Publication
elisa.hashnode.dev › split-a-dataframe
Split a Pandas Dataframe in Python - Elisa's Blog - Hashnode
September 29, 2021 - split the dataframe into two parts: its first N rows (or a percentage of the number of rows) and the rest; split it randomly into two parts, by a number of rows or percentage. As example data, I will use my Spotify streaming history during some ...
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › split pandas dataframe by column value
Split Pandas DataFrame by Column Value - Spark By {Examples}
June 27, 2025 - The Pandas DataFrame can be split into smaller DataFrames based on either single or multiple-column values. Pandas provide various features and functions
🌐
Medium
medium.com › @amit25173 › how-to-split-dataframe-into-chunks-in-pandas-6c1282e31552
How to Split DataFrame into Chunks in Pandas? | by Amit Yadav | Medium
March 6, 2025 - If you’re just starting out, this is the easiest method to split your DataFrame. NumPy’s array_split() handles everything for you, even when the data isn't evenly divisible. 🔹 How does it work? It automatically distributes rows across chunks, even if the total number of rows isn’t a multiple of the chunk size. import pandas as pd import numpy as np # Sample DataFrame df = pd.DataFrame({'A': range(1, 11), 'B': range(11, 21)}) # Splitting into 3 chunks chunks = np.array_split(df, 3) # Displaying chunks for i, chunk in enumerate(chunks): print(f"Chunk {i+1}:\n", chunk, "\n")
🌐
Statistics Globe
statisticsglobe.com › home › python programming language for statistics & data science › slice pandas dataframe by index in python (example)
Slice pandas DataFrame by Index in Python | Split & Create Two Subsets
July 22, 2022 - data_upper = data.iloc[:split_point] # Create upper data set print(data_upper) # Print DataFrame of upper rows · After executing the previous syntax the pandas DataFrame subset shown in Table 2 has been created.
🌐
IncludeHelp
includehelp.com › python › split-cell-into-multiple-rows-in-pandas-dataframe.aspx
Python - Split cell into multiple rows in pandas dataframe
# Importing pandas package import pandas as pd # Importing display attribute from Ipython from IPython.display import display # Creating a dictionary d = { "Product_id":[1,3,7], "Product_code":["#101,#102,#103","#104","#105,#106"], "Manufacturing_date":["22/6/2018","21/8/2019","27/11/2020"], "Cities":["c1,c2,c3","c4","c5,c6"] } # Creating a DataFrame df = pd.DataFrame(d) # Display Original DataFrames print("Created DataFrame:\n",df,"\n") # splitting cities column res = df.set_index(['Product_id', 'Product_code']).apply(lambda x: x.str.split(',').explode()).reset_index() # Display result print("Result:\n",res)