[Python] How can I verify the value of a dataframe element?

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

  1. Stack

    Stack Membro Participativo

    I'm trying to use an if to verify if a value in a dataframe equals a certain value i got before. Here's an extract of the dataframe:

    usager heures demandes heure arrivée ascenseur heures arrivée étage \
    0 1181.0 2019-04-27 07:00:27 2019-04-27 07:00:27 2019-04-27 07:00:43
    1 1181.0 2019-04-27 12:11:54 2019-04-27 12:12:10 2019-04-27 12:12:26
    2 1181.0 2019-04-27 12:55:52 2019-04-27 12:56:06 2019-04-27 12:56:22
    3 1181.0 2019-04-27 17:25:49 2019-04-27 17:26:05 2019-04-27 17:26:21
    0 826.0 2019-04-27 07:00:50 2019-04-27 07:00:50 2019-04-27 07:00:59
    .. ... ... ... ...
    3 677.0 2019-04-27 17:38:47 2019-04-27 17:39:17 2019-04-27 17:39:34
    0 667.0 2019-04-27 09:59:38 2019-04-27 09:59:54 2019-04-27 10:00:09
    1 667.0 2019-04-27 12:23:24 2019-04-27 12:23:39 2019-04-27 12:23:54
    2 667.0 2019-04-27 13:25:16 2019-04-27 13:25:28 2019-04-27 13:25:43
    3 667.0 2019-04-27 18:01:03 2019-04-27 18:01:18 2019-04-27 18:01:33

    mode transport etage_demandes attente temps dans ascenseur anomalie
    0 Ascenseur 33.0 0.0 16.0 False
    1 Ascenseur 0.0 16.0 16.0 False
    2 Ascenseur 33.0 14.0 16.0 False
    3 Ascenseur 0.0 16.0 16.0 False
    0 Ascenseur 18.0 0.0 9.0 False
    .. ... ... ... ... ...
    3 Ascenseur 0.0 30.0 17.0 False
    0 Ascenseur 30.0 16.0 15.0 False
    1 Ascenseur 0.0 15.0 15.0 False
    2 Ascenseur 30.0 12.0 15.0 False
    3 Ascenseur 0.0 15.0 15.0 False


    With 'usager' being an unique id for each person, i'm trying to find the level where each person works which is shown in etage_demandes when it's not null. Each row in the dataframe is a movement from a level to another and each person moves 4 times.

    Because of how the dataframe is made I tried to do this:

    memory=0
    print(df['usager'][1:2])
    etage_travail=[df[:0]['etage_demandes']]
    for i in range (4,len(df['usager'])):
    if (df['usager'][i-1:i]=!memory):
    memory=df['usager'][i-1:i]
    for i in range (0,4):
    etage_travail.append(df[i-1:i]["etage_demandes"])



    Where I go through each row and get the work level for each person when the id is not the same as the id of the row before. but I can't seem to write the condition in a way so that it works.

    Continue reading...

Compartilhe esta Página