Jump to content
We've recently updated our Privacy Statement, available here. ×
  • FAQ: Python Data Functions in Spotfire®


    This article collects questions and answers related to the native Python data functions introduced in Spotfire® 10.7. The article is divided into sections for different categories of questions.

    General

    Does Spotfire come with its own Python interpreter?

    Yes, Spotfire Analyst bundles a Python interpreter. You can find it in the Modules folder of your Spotfire installation directory.

    converted-file.png.9241b3f014d928b3f653f5f39f630955.png

    Can I use a specific python interpreter that I installed on my computer instead of the one that is bundled with Spotfire?

    Yes, in Tools -> Options -> Data functions in Spotfire Analyst you can set a path to a locally installed Python interpreter. Please note that in this case, you will need to make sure the locally installed Python environment has the required packages.

    We previously used the Python Data function extension and since we upgraded to Spotfire 10.7+ we cannot run or edit the data functions we already had created. What do we need to do?

    This will happen if you do not install the Python Data function extension on your Spotfire 10.7 system. Even though 10.7 has native python data functions, these are not the same as the data functions created using the extension. The Python Data Function extension is not part of the regular Spotfire installation, and if you need to run and edit data functions that are created using the extension you need to add the extension to Spotfire 10.7 (or if you are using a later version). 

    I want to migrate the Python data functions that I created using the Python Data function extension to the native python data functions. How do I go about this?

    You need to copy the code from your original data function, create a new native python data function and paste the code into it, define the corresponding inputs and output parameters, and if you are lucky that is it. If you are not that lucky, you may have to make sure the right packages are available in the native Python interpreter, and possibly you may have to modify the code to some extent as guided by the error messages.

    Can the Spotfire Web Player and Automation Services use Python Data functions?

    Edit: Yes - as of Spotfire 10.10 LTS this is possible through the Spotfire Service for Python. Read more in the What's New in Spotfire® 10.10 LTS article.

    Where can I read more about Python data functions in Spotfire?

    Spotfire Data Function Library: Python and R Scripts for Data Analysis is a good starting point. This is a top-level article that links to a few other articles and documentation on specific subjects.


    Inputs and outputs

    How are inputs and outputs from Spotfire columns, tables, etc represented in a Python data function?

    When you define inputs and outputs to a data function, you can set them to be of the Spotfire type Value, Column or Table. In all cases, in your Python code, they are referred to by the name you defined. So if you name an input of type value "inputValue", you will refer to it in your python code as "inputValue", like if inputValue > 3: ...

    The Python type of the inputs and outputs will vary based on the type of the input:

    Value: this will be a Python int, float, or str dependent on the type of the value.

    Column: this will be a Pandas Series

    Table: this will be a Pandas DataFrame

    Read more detail about the mapping of Python data types to Spotfire data types in the section Spotfire and Python data type mapping of this document.


    Python Package Management

    How do I add other packages to be used with my Python data functions?

    You use the command line pip utility with the bundled Python interpreter, like >python.exe -m pip install nltk. Read more in this article.

    Note that in Spotfire 10.8 and later you can also use the Python tools located in Tools->Python tools from Spotfire Analyst.

    Can I somehow make sure all my users use the same Python packages when developing data functions for Spotfire?

    You can create a Spotfire .spk file that bundles a set of Python packages and is deployed to each user as part of the regular Spotfire package deployment mechanism. Read more about this in the documentation and in this article.

    What packages are included with the bundled Python interpreter?

    Bitstring, NumPy, pandas, and a couple more. Please read the documentation for a comprehensive list. Look for the document Python Data functions in Spotfire Analyst.

    Can I distribute a Python package we have developed internally in our company using the Spotfire package deployment mechanism? The Python package we have developed is not available via pip.

    Yes, when creating your .spk you can include a package from a different repository or in local a file path. In the requirements.txt file use the option -i or --index-url, followed by the location URL.

    #example

    mylib -i http://my.domain.org/lib/1.0.0/mylib/

    Also, see the documentation and this article.

    When I use the "Python tools" (located in the Tools menu of Spotfire Analyst) to install packages, where are Python tools looking for the packages?

    Python tools by default look for packages in the PyPI repository. Python tools use PIP "under the hood". If it is desired to have PIP point to a different repository than PyPI, PIP can be configured to look for packages in other locations. Please refer to the pip documentation: https://pip.pypa.io/en/stable/user_guide/#configuration


    Machine learning

    If I have trained a model using a data function, how can I make use of it for prediction in other data functions?

    You can store a trained model in a document property using the pickle package. See the chapter "Using a Model Produced in a Previous Data Function" in the documentation


    Python in Earlier versions of Spotfire

    I have an earlier version of Spotfire. Can I use Python in some other way?

    Yes. Python can be called through IronPython or via TERR data functions as alternatives for those users on an older version. However, it is highly recommended to upgrade to the latest LTS version which has Python built into it natively and is actively supported.

    • Confused 1

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...