0

I have a dataframe data. I have a column data['T'] and a column data['p']. When using a function called TPFLSHdll I get the following error TypeError: cannot convert the series to <class 'float'> The code is the following:

import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

# connetto Python alle librerie REFPROP (prende in automatico la cartella)
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])

RP.SETUPdll(1, 'WATER.FLD', "HMX.BNC","DEF")

D, Dl, Dv, x, y, q, e, h, s, Cv, Cp, w, ierr, herr = RP.TPFLSHdll(data['T'], data['P'], [1])

I experienced a similar trouble in the past, solved in the following:

import os
from ctREFPROP.ctREFPROP import REFPROPFunctionLibrary

# connetto Python alle librerie REFPROP (prende in automatico la cartella)
RP = REFPROPFunctionLibrary(os.environ['RPPREFIX'])
RP.SETPATHdll(os.environ['RPPREFIX'])

RP.SETUPdll(1, 'WATER.FLD', "HMX.BNC","DEF")

D, Dl, Dv, x, y, q, e, h, s, Cv, Cp, w, ierr, herr = RP.TPFLSHdll(data['T'].values, data['P'].values, [1])

This solution to add .values doesn't work and I get the following TypeError: only size-1 arrays can be converted to Python scalars

Any suggestion to avoid FOR cycle?

  • you cannot. Vectorization relies on using pandas/numpy built-in functions. – juanpa.arrivillaga Apr 01 '23 at 18:25
  • your function clearly expects a float as an argument, you cannot magically make it work on array inputs. And if you have a python-level function, you cannot really get much speed gains if you want to apply it to every element. Here are some alternatives: https://stackoverflow.com/questions/35215161/most-efficient-way-to-map-function-over-numpy-array – juanpa.arrivillaga Apr 01 '23 at 18:27

0 Answers0