Predictive Hacks

How to split a Pandas Dataframe into equal parts

We can use numpy to split a dataframe into N equal parts as follows:

import pandas as pd
import numpy as np


Now let’s split the Dataframe into 3 equal parts.

df_split = np.array_split(df, 3)

Now you can treat the df_split as a list of dataframes.


Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore


Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.


Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s