[Python] behavior of appending a series to a list

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    lets say i have the following:

    rows_list = []

    for index,row in df.iterrows():
    .
    .
    .
    rows_list.append(row)


    where rows_list is a list and row is a Series

    when i do something like rows_list[1] i seem to get the columns for the data in question. IE it is displaying the data like a series, but its a list: e.g.

    rows_list[1]

    produces

    id 1234

    where I would expect it would just show 1234

    what i want to do is search the list/series for a specific value, but I'm running into trouble.

    type(rows_list)

    shows

    list

    whereas if i do

    john in rows_list

    shows

    ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

    specifically this works 'test' in rows_list[1].loc['id'] but I want to do something like 'test' in rows_list[:].loc['id']

    Continue reading...

Compartilhe esta Página