Search code examples
pythonpandastransformation

I have tried almost everything, Python Data Transformation into a range, but keep getting *Int object not callable*


I'm trying to transform a column, into a range from 1 to 100, however I keep getting " int object is not callable "

df['r'] = df['r']. apply (lambda x : (100 - 1)((x-min(df['r']))/((max(df['r'])) - min(df['r'])) + 1

Returns 'int' object not callable


Solution

  • In Python, a value followed by parentheses denotes a function call.

    So, when Python sees this:

    (100 - 1)((x-min(df['r']))
    

    ... it simplifies to this:

    99((x-min(df['r']))
    

    ... and it thinks you're trying to use 99(...) as a function call.

    In common mathematical notation, (a)(b) means "a multiplied by b", but Python doesn't use that notation. You need an explicit * symbol for multiplication:

    (100 - 1)*((x-min(df['r']))