[Python] I am trying to create a seperate data frame when specific conditions are met...

Discussão em 'Python' iniciado por Stack, Agosto 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have a data frame that consists of a column that contains the Gender data. I want to segregate it by gender and create 2 seperate dataframes.

    I tried to do this by implementing the code below:

    for i in range(len(a1)):
    if a1['Gender'] == "Male":
    a2=a2.merge(a1.iloc)
    else:
    a3=a3.merge(a1.iloc)


    But it always throws an error of:

    'Series' object has no attribute 'merge'


    I also tried this:

    for i in range(len(a1)):
    if a1['Gender'] == "Male":
    a2=a1.iloc
    else:
    a3=a1.iloc


    Which worked but the problem with this was that it will overwrite the previous data stored in any of the child data frames. I have tried using .concat() too but that didn't work either. My End goal is to create 2 dataframes segregated by Gender.

    Continue reading...

Compartilhe esta Página