Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
HamidBee
Power Participant
Power Participant

Power BI Python Script Out of Memory Error When Truncating DataFrame

Hello,

 

I'm encountering an out of memory error when trying to run a Python script within Power BI to manipulate a dataset. I aim to truncate a dataset to only the first 5 rows using a Python script step in the Power Query Editor. Here's the script I am using:

import pandas as pd

# 'dataset' holds the input data for this script
# Keep only the first 5 rows
dataset = dataset.head(5)

 

 

However, when I execute the script, I receive the following error message:

 
DataSource.Error: ADO.NET: Python script error.
pandas.errors.ParserError: Error tokenizing data. C error: out of memory
Details:
DataSourceKind=Python
DataSourcePath=Python
Message=Python script error.
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException

 

The dataset is not particularly large, so it's puzzling why this memory issue arises. I've tried to ensure that my system has enough available memory and even filtered the dataset in Power Query before handing it off to Python, but to no avail.

 

Has anyone faced a similar issue or can offer insights into what might be going wrong? Any advice on how to troubleshoot this error would be greatly appreciated.

 

Thank you in advance for your help!

2 REPLIES 2
lbendlin
Super User
Super User

Do you see the same issue when keeping the top 5 rows in Power Query?

mahenkj2
Solution Sage
Solution Sage

Hi @HamidBee ,

 

I really don't have experience of using it, but could you confirm the format of retrieved lines, it looks to be basically a parsing error.

 

A basic search on this error in internet indicate, it's common error related to formating.

 

Hope it helps.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.