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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Power query python dataset from an other table

Hello,

 

I have a table called "mytab" contaning a column "Expression" like this :

 

RM5280_0-1594997038689.png

 

I am writing a python script (a regex function) in "mytab2" which need to import "expression" from "mytab" in a pandas dataframe list.

I'd like to do some thing like this :

 

import pandas as pd

myListOfExpression = pd.DataFrame(['mytab'].dataset['Expression'],columns=['Expression1'],dtype=float)

 

I know that he red ['mytab']. is wrong, but I try to specify the table "mytab".

 

Any idea ?

 

Thanks

 

2 REPLIES 2
ImkeF
Community Champion
Community Champion

Hi @Anonymous ,

the python-script will sit in a Python.Execute function in PQ. It will be escaped in there. In order to integrate some objects from the M-world, you have to unescapce the script and combine with ampersand "&":

 

Python.Execute ( "import pandas as pd

myListOfExpression = pd.DataFrame( " & mytab & "dataset['Expression'],columns=['Expression1'],dtype=float)

 

This syntax is probably wrong, as "mytab" returns the whole table, but this is the general principle on how to combine M-objects with python scripts.

 

mytab[Expression] would return a list with the column contents BTW. 

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hello, 

 

thanks for your answer !

 

I tried what you said, but it doesn't works :

 

i try this : = Python.Execute("import pandas as pd#(lf)#(lf)myListOfExpression = pd.DataFrame("&[mytab]&"dataset['Expression'],dtype=float)",[dataset=#"Colonnes renommées"])

 

I have this answer : We have detected an unknown identifier. Did you use the shortened syntax [field] for a _[field] outside of a "each" expression?

 

I also tried ["mytab"], ['mytab'] but don't work either.

 

Any idea ?

 

Thanks

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.