Python Matlab engine: How to pass a pandas dataframe to Matlab function?
Hi everyone,
I’d like to pass a Python Pandas dataframe to a Matlab function. E.g.:
>>> DATAFILE = "2024-05-28_11-30-06.parquet"
>>> import matlab.engine
>>> import pandas as pd
>>> eng = matlab.engine.start_matlab()
>>> df = pd.read_parquet(DATAFILE)
>>> eng.table(df)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:Userssomeonevenvmatlab2Libsite-packagesmatlabenginematlabengine.py", line 64, in __call__
future = pythonengine.evaluateFunction(self._engine()._matlab,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported Python data type: pandas.core.frame.DataFrame
Do I miss a conversion step?
Doing the same from Matlab works:
>> pyenv(‘Version’,’C:Userssomeonevenvmatlab2Scriptspython.exe’,’ExecutionMode’,’OutOfProcess’)
ans =
PythonEnvironment with properties:
Version: "3.11"
Executable: "C:Userssomeonevenvmatlab2Scriptspython.exe"
Library: "C:UserssomeoneAppDataLocalProgramsPythonPython311python311.dll"
Home: "C:Userssomeonevenvmatlab2"
Status: NotLoaded
ExecutionMode: OutOfProcess
>> df = py.pandas.read_parquet("2024-05-28_11-30-06.parquet");
>> t = table(df)
t =
300000×6 table
Thanks in advance!
Best regards,
StefanHi everyone,
I’d like to pass a Python Pandas dataframe to a Matlab function. E.g.:
>>> DATAFILE = "2024-05-28_11-30-06.parquet"
>>> import matlab.engine
>>> import pandas as pd
>>> eng = matlab.engine.start_matlab()
>>> df = pd.read_parquet(DATAFILE)
>>> eng.table(df)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:Userssomeonevenvmatlab2Libsite-packagesmatlabenginematlabengine.py", line 64, in __call__
future = pythonengine.evaluateFunction(self._engine()._matlab,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported Python data type: pandas.core.frame.DataFrame
Do I miss a conversion step?
Doing the same from Matlab works:
>> pyenv(‘Version’,’C:Userssomeonevenvmatlab2Scriptspython.exe’,’ExecutionMode’,’OutOfProcess’)
ans =
PythonEnvironment with properties:
Version: "3.11"
Executable: "C:Userssomeonevenvmatlab2Scriptspython.exe"
Library: "C:UserssomeoneAppDataLocalProgramsPythonPython311python311.dll"
Home: "C:Userssomeonevenvmatlab2"
Status: NotLoaded
ExecutionMode: OutOfProcess
>> df = py.pandas.read_parquet("2024-05-28_11-30-06.parquet");
>> t = table(df)
t =
300000×6 table
Thanks in advance!
Best regards,
Stefan Hi everyone,
I’d like to pass a Python Pandas dataframe to a Matlab function. E.g.:
>>> DATAFILE = "2024-05-28_11-30-06.parquet"
>>> import matlab.engine
>>> import pandas as pd
>>> eng = matlab.engine.start_matlab()
>>> df = pd.read_parquet(DATAFILE)
>>> eng.table(df)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:Userssomeonevenvmatlab2Libsite-packagesmatlabenginematlabengine.py", line 64, in __call__
future = pythonengine.evaluateFunction(self._engine()._matlab,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: unsupported Python data type: pandas.core.frame.DataFrame
Do I miss a conversion step?
Doing the same from Matlab works:
>> pyenv(‘Version’,’C:Userssomeonevenvmatlab2Scriptspython.exe’,’ExecutionMode’,’OutOfProcess’)
ans =
PythonEnvironment with properties:
Version: "3.11"
Executable: "C:Userssomeonevenvmatlab2Scriptspython.exe"
Library: "C:UserssomeoneAppDataLocalProgramsPythonPython311python311.dll"
Home: "C:Userssomeonevenvmatlab2"
Status: NotLoaded
ExecutionMode: OutOfProcess
>> df = py.pandas.read_parquet("2024-05-28_11-30-06.parquet");
>> t = table(df)
t =
300000×6 table
Thanks in advance!
Best regards,
Stefan python, pandas MATLAB Answers — New Questions