1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Applying a function to two columns in a data frame

Discussão em 'Python' iniciado por Stack, Outubro 5, 2024 às 22:52.

  1. Stack

    Stack Membro Participativo

    I want to create new columns in a data frame containing biking data (start station and end station names, and trip duration). I want to assign the different stations to a specific neighborhood. However, I am not managing to apply the function to both the start station and end station columns. I would appreciate any guidance. Below is my code:

    #Assign stations to neighborhood

    Shadyside = ['Ivy St & Walnut St', 'Shady Ave & Ellsworth Ave','S Negley Ave & Centre Ave','Penn Ave & S Whitfield St',
    'Pierce St & Summerlea St']

    #print(Shadyside)
    def station(x):
    for i in Shadyside:
    #print(i)
    if re.search(r'i', x) != None:
    return 'Yes'
    else:
    return 'No'
    Biking_data['Shadyside'] = Biking_data['Start Station'].apply(station)
    print(Biking_data)


    I tried the above code just on one column to see if the function works. But then stations not in Shadyside are said to be in the neighborhood.

    Continue reading...

Compartilhe esta Página