Reputation: 1352
I am trying to use apply function in data frame.
Below is the sample data frame.
import pandas as pd
from CoolProp.HumidAirProp import HAPropsSI
df =pd.DataFrame()
df['T'] = [23,35,55]
df ['RH'] = [50,70,35]
df['H']= df.apply(lambda x: HAPropsSI('H','T',x ['T']+273.15, 'P',101325,'R',x ['RH']/100), axis = 1)
The actual data frame contains 400,000 rows and 8 columns. When I apply the abovementioned function in my actual data frame, it takes long time to complete. Are there any other ways, which can enhance the computing speed?
I tried to use the vetorization as follow:
df ['Enthalpy'] = np.vectorize(HAPropsSI) ('H','T',df ['T']+273.15, 'P',101325,'R',df ['RH']/100)
It shows the following error:
TypeError: Numerical inputs to HAPropsSI must be ints, floats, lists, or 1D numpy arrays.
The input for the function is as follow:
HAPropsSI('H',T',x ['T']+273.15,P',101325,'R',x ['RH']/100)
The first parameter, H is the parameter that I want to find.
The second para, T is the type of input para required and the third is the value of input para T.
The third and the fourth represent the type of input para and its value. Similar applies to the fifth and the sixth.
Upvotes: 0
Views: 792
Reputation: 23
Have you tried to vectorize your function?
I would recommend the answers to this question here, which explain the advantages of "fake" and "true" vectorization very well.
Upvotes: 1