'Creating dummy variable based on value counts in a function

I'm trying to assign 0 to string that is more frequent and 1 to less frequent string in a function. My idea is that it should take any column with binary string and based on value count assign 0 and 1. How can i do that?


data = {'status':["Default", "Non-Default", "Non-Default", "Non-Default", "Default", "Non-Default"]}
df = pd.DataFrame(data)
df

        status
    0   Default
    1   Non-Default
    2   Non-Default
    3   Non-Default
    4   Default
    5   Non-Default


    df.value_counts()

    status     
    Non-Default    4
    Default        2
    dtype: int64



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source