1

Hi I am trying to calculate a ratio using lambda function.

This is the code.

ratio = lambda w,x,y,z: ((z*1000*y/3600)/1.05506)/((w*35.32)*x)

df32[('Enthalpy vs DB Ratio','btu')]= df32[[('HRSG DB Flow','T/Hr'),
('Gas calorific value','BTU/Scf'),('HRSG HP STEAM Enthalpy','Kj/Kg'),
('HRSG HP STEAM FLOW','T/h')]].apply(ratio)

I am getting

TypeError: () missing 3 required positional arguments: 'x', 'y', and 'z'

can someone please help? Is this formula problem or it is related to the database problem I am working on?

Thanks for your time.

1
  • @ Michael Szczesny I got your point. I used with axis=1 now. Thanks. Commented Feb 16, 2022 at 9:21

1 Answer 1

1

You cant use unpacking, but is possible use indexing. Also add axis=1 for processing per rows:

ratio = lambda x: ((x[3]*1000*x[2]/3600)/1.05506)/((x[0]*35.32)*x[1])

df32[('Enthalpy vs DB Ratio','btu')]= df32[[('HRSG DB Flow','T/Hr'),
                                            ('Gas calorific value','BTU/Scf'),
                                            ('HRSG HP STEAM Enthalpy','Kj/Kg'),
                                            ('HRSG HP STEAM FLOW','T/h')]]
                                            .apply(ratio, axis=1)

Faster/vectorized is use:

df32[('Enthalpy vs DB Ratio','btu')] = ((df32[('HRSG HP STEAM FLOW','T/h')]*1000*df32[('HRSG HP STEAM Enthalpy','Kj/Kg')]/3600)/1.05506)/((df32[('HRSG DB Flow','T/Hr')]*35.32)*df32[('Gas calorific value','BTU/Scf')])

Or for better readibility use:

a = df32[('HRSG HP STEAM FLOW','T/h')]
b = df32[('HRSG HP STEAM Enthalpy','Kj/Kg')]
c = df32[('HRSG DB Flow','T/Hr')]
d = df32[('Gas calorific value','BTU/Scf')]

df32[('Enthalpy vs DB Ratio','btu')] = ((a*1000*b/3600)/1.05506)/((c*35.32)*d)
Sign up to request clarification or add additional context in comments.

2 Comments

@ jezrael i tried both solution and are working fine. As you mentioned the second option is very fast. Thanks for detailed explanation.
Third option make more sense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.