Home > Blockchain >  Lambda function positional argument error
Lambda function positional argument error

Time:02-16

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.

CodePudding user response:

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)
  • Related