0

I'm using pandas to filter results from a column in the worksheet, and I need to assign some values to variables, but I can't

My code snippet below makes the filter

variable = clientes.loc[(clientes['Data']=='08/02/2023')]
print(variable)

Below the result

 Nome do paciente        Data Horário  Email     Telefone Tipo de agendamento           Situação Status Financeiro Observação
34          Teste 1  08/02/2023   10h00    NaN          NaN                 NaN  Paciente agendado          Não pago        NaN
35          Teste 2  08/02/2023   13h30    NaN          NaN                 NaN  Paciente agendado          Não pago        NaN
36          Teste 3  08/02/2023   15h00    NaN   55544454.0    Consulta Simples  Paciente agendado          Não pago        NaN
37          Teste 4  08/02/2023   18h00    NaN  555445454.0    Consulta Simples  Paciente agendado          Não pago        NaN
38          Teste 5  08/02/2023   20h00    NaN          NaN                 NaN  Paciente agendado          Não pago        NaN

Below are the values I need to assign to a variable. ideally a list

   Nome do paciente      Data      Horário
    Teste 1            08/02/2023   10h00
    Teste 2            08/02/2024   13h30
    Teste 3            08/02/2025   15h00
    Teste 4            08/02/2026   18h00
    Teste 5            08/02/2027   20h00

I checked the solution from the link below, but I couldn't adapt it to my code

Pandas assigning value to variable with two column filters from dataframe

2
  • Hello @Brandalize. Please provide the solutions you have tried so far, or other SO (Stack Overflow) solutions you may have looked at but didn't work. Commented Feb 8, 2023 at 12:44
  • Hello @LoukasPap. I just updated the question by inserting what I tried Commented Feb 8, 2023 at 12:47

1 Answer 1

1

You are not specifying the columns which you need. Try the below code.

variable = clientes.loc[(clientes['Data']=='08/02/2023')][['Nome do paciente',       'Data', 'Horário']]

print(variable)

final_list = []

[final_list.extend(i) for in variable.values.tolist()]

print(final_list)

final_list will give you the list like below

['Teste 1', '08/02/2023', '10h00', 'Teste 2', '08/02/2024', '13h30'...................]

Sign up to request clarification or add additional context in comments.

3 Comments

This brought me just the columns I wanted. But I still need to assign these values to variables.
Each column to a variable or each row or each value?
Each column is a list variable. Or better yet, a single list variable with all values being index separated by lines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.