[Python] Why is my Winsorization code telling me it has too many arguments?

Discussão em 'Python' iniciado por Stack, Março 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have an array that looks like this:

    [ 3.4 0. 10.6 ... -0.4 -0.4 0. ]


    The array has around 13.5m values in it. I want to winsorize the top and bottom 5% to deal with outliers. This is the code I'm using:

    from scipy.stats.mstats import winsorize
    winsorized_array = winsorize(array, (0.05, 0.05))


    However, this returns the following error message:


    TypeError: winsorize() takes 1 positional argument but 2 were given
    ​

    I've also tried the following variation:

    from scipy.stats.mstats import winsorize
    winsorized_array = winsorize(array, limits = [0.05, 0.05])


    This returns the following error message, which doesn't make any sense to me, since as far as I can tell this is the same syntax found in the scipy documentation here:


    TypeError: winsorize() got an unexpected keyword argument 'limits'
    ​

    Does anyone know what I'm doing wrong please?

    Continue reading...

Compartilhe esta Página