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
thomas9921
Frequent Visitor

Python script works in Jupyter Notebook but not Power BI Desktop

Hello, I am able to run the first script below in Jupyter but when I run it in python I get "the preview for section 1/query1/source doesn't exist".

I have checked my settings in PBI and have all the packages installed on my machine. In fact I am running a very similar script with the same definition successfully. However when I add the last 5 lines of code I get the error. 
I read it could be the size of the output but the output is 300 rows with 2 columns. 

Your help is greatly appreciated!

 

import stripe
import pandas as pd
from datetime import datetime
import numpy as np


stripe.api_key = ''
stripe.api_version = "2020-08-27"


df_lookup = pd.DataFrame(columns=['payout_id', 'charge_id'])

 

def stripe_get_data(resource, start_date=None, end_date=None, **kwargs):
if start_date:
# convert to unix timestamp
start_date = int(start_date.timestamp())
if end_date:
# convert to unix timestamp
end_date = int(end_date.timestamp())
resource_list = getattr(stripe, resource).list(limit=100, created={"gte": start_date,"lt": end_date}, **kwargs)
lst = []
for i in resource_list.auto_paging_iter():
lst.extend([i])
df = pd.DataFrame(lst)
if len(df) > 0:
df['created'] = pd.to_datetime(df['created'], unit='s')
return df

 

for i in stripe_get_data('Payout')['id'].tolist():
balance_transactions = stripe.BalanceTransaction.list(payout=i, expand=['data.source'], type='charge')
for txn in balance_transactions.data:
charge = txn.source
df_lookup = df_lookup.append({"payout_id":i,"charge_id":charge.id}, ignore_index = True)

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@thomas9921 , Refer the old solution

https://community.powerbi.com/t5/Desktop/Python-script-error-quot-the-preview-for-section-1-query1-s...

 

Or refer to the steps and description of the video for various errors

 

How to make Python work with Power BI: https://youtu.be/5D0BkNsu5CM

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@thomas9921 , Refer the old solution

https://community.powerbi.com/t5/Desktop/Python-script-error-quot-the-preview-for-section-1-query1-s...

 

Or refer to the steps and description of the video for various errors

 

How to make Python work with Power BI: https://youtu.be/5D0BkNsu5CM

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.