For those wishing to use the versatile Python Scripting extension, the following Installation and Getting Started notes should help...
The "Execute Python" operator accesses your installed version of Python version by specifying the path under "Settings" -> "Preferences..." -> "Python Scripting" -> "Path to Python executable":
For example, the screenshot shows a typical path specification using Python from Anaconda installed in Windows. Now you can access libraries installed for this Python version in the operator by importing them like you're used to do in Python.
The Python code in the operator uses 4 spaces as one indentation level. So if you receive indentation errors make sure the indentation equals 4 times the indentation level desired. For example, when I copy the code of your "rm_main" it contains a mixture of tabs and spaces, as well as indentations consisting of only 2 spaces. Some editors (like sublime for example) offer the option to display whether tabs or spaces are used.
After dealing with the indentation error make sure to form a proper Pandas DataFrame object. I looked into the "nmrglue" library and the "fileio.bruker.read_pdata" method seems to already return a dictionary of the given data. Fortunately Pandas DataFrames take that as an input. So you might directly create a DataFrame out of the returned object. This even has the advantage, that columns are properly named from the beginning.
Now having your Pandas DataFrame instance you can deliver that in the return statement of your "rm_main" function. Afterwards the "Execute Pyhton" Operator converts the DataFrame to an Example Set (which is used for RapidMiner to manage matrix like data). You can access this Example Set at the Operators Outputport. The first DataFrame returned is delivered at the top most Output Port and so on.
Here is some example code, where you only need to adjust the path to the file you want to read:
import nmrglue as ng import pandas as pd def rm_main(): path = "C:\\my_great_data_file.ending" // read data using nmrglue from file located at path dic, _ = ng.fileio.bruker.read_pdata(path) // create pandas data frame from the given dictionary df = pd.DataFrame(dic) // check if data frame creation worked if not isinstance(df, pd.DataFrame): print("Conversion to data frame failed.") // deliver the data frame to the operators output port return df
For further reading, check out Thomas Ott's excellent blog article on using R and Python scripts in RapidMiner.
Thanks and enjoy coding!
RapidMiner Research, Dortmund