Execute Power Query by passing arguments to Python

There is a way to execute Power Query by passing parameters to Python. I will try to write this code.

argv2table.py


import pandas as pd
import csv
my_argv = [r'MY_ARGVS']
l = list(csv.reader(my_argv, delimiter=' '))[0]
df = pd.DataFrame(l, columns=['argv'])

The point to note here is that the MY_ARGVS part at the beginning will be replaced later, so it should never appear again in the code.

In Power Query write

(argv) =>
    let
        Source = Text.FromBinary(File.Contents("c:\temp\argv2table.py")),
        rep = Text.Replace(Source, "MY_ARGVS", argv),
        pyexe = Python.Execute(rep),
        df1 = pyexe{[Name="df"]}[Value]
    in
        df1

Do this and try putting the appropriate parameters separated by spaces. image.png This way, a table consisting of each parameter is returned. image.png Since it is divided by csv.reader, it is possible to quote by double quotation. If you pass the Parameter of Power BI, you can change the argument passed to Python from the report screen. However, its practicality is questionable because it asks for Maidomaido Permission.

Recommended Posts

Execute Power Query by passing arguments to Python
Push notification from Python server to Android
Push notification to Intel Edison
Execute Power Query by passing arguments to Python
Execute Python function from Powershell (how to pass arguments)
exec, eval to execute [python] statement
Story of power approximation by Python
Reintroduction to Python Decorators ~ Learn Decorators by Type ~
All Python arguments are passed by reference
Answer to AtCoder Beginners Selection by Python3
Function to save images by date [python3]
[Python / Tkinter] How to pass arguments to command
[python] How to display list elements side by side
How to receive command line arguments in Python
Automatically register function arguments to argparse in Python
Try to forecast power demand by machine learning
I want to memoize including Python keyword arguments
[Bash] Use here-documents to get python power from bash
How to erase the characters output by Python
[Python] How to sort instances by instance variables
I want to sell Mercari by scraping python
[Python] Continued-Convert PDF text to CSV page by page
Updated to Python 2.7.9
How to execute a schedule by specifying the Python time zone and execution frequency
Log in by passing the login session cookie obtained by Python requests to the Selenium browser.
"Backport" to python 2
[Keras] Personal memo to classify images by folder [Python]
List of posts related to optimization by Python to docker
[Introduction to Udemy Python3 + Application] 53. Dictionary of keyword arguments
Set constructor keyworded arguments to mock attributes in Python
Specifies the function to execute when the python program ends
How to save a table scraped by python to csv
How to execute a command using subprocess in Python
[Introduction to Udemy Python3 + Application] 52. Tupleization of positional arguments
Query from python to Amazon Athena (using named profile)