[Python] Data-frame to show selected results only from columns divisions

Discussão em 'Python' iniciado por Stack, Junho 8, 2025.

  1. Stack

    Stack Membro Participativo

    A data-frame to divide the month columns by the Total column. At the end, I want to only show the results greater than 35% (0.35).

    import pandas as pd

    data = {'Name' : ["John","Peter","Kate","Liz"],
    'Jan-2016': [408,88,277,32],
    'Feb-2016': [313,348,73,302],
    'Mar-2016': [497,197,196,164],
    'Apr-2016': [88,87,447,118],
    'May-2016': [79,20,235,273],
    'Total': [1385,740,1228,889]}

    df = pd.DataFrame(data)

    df_1 = df[["Jan-2016","Feb-2016","Mar-2016","Apr-2016","May-2016"]].div(df["Total"], axis=0)


    [​IMG]

    I can only work out the calculation.

    What's the way to output the results greater and equal to 0.3 only? (please note 1 person may have 0-3 columns fit).

    Continue reading...

Compartilhe esta Página