[Python] Creating a new column by counting element in range of rows using Python

Discussão em 'Python' iniciado por Stack, Abril 16, 2025.

  1. Stack

    Stack Membro Participativo

    I am creating a permutation that contains WL for each Match as follow:

    N_Match = 3
    data = pd.DataFrame(list(itertools.product("WL", repeat=N_Match)))


    Since I used N_match = 3 the output of dataframe will have 3 columns: I would like to count number of W and L for each row in all columns.

    I will create a new column as follows: If number of W is greater than no. of L, the formula that I will use for the cell is 1/2^(N_Match), else 0

    How can I create that column as shown in the following sample:

    [​IMG]

    in this case, 0.125 is calculated as 1/2^N_Match.

    Continue reading...

Compartilhe esta Página