1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Applying group by then condition

Discussão em 'Python' iniciado por Stack, Setembro 8, 2025.

  1. Stack

    Stack Membro Participativo

    How can the value of 'same_month=yes' be updated for entries grouped by "code" when the "Date" is identical?

    below are examples of the data frame

    import pandas as pd

    df = pd.DataFrame([[1,'2023-01-02 00:00:00','01','2023',''],
    [2,'2023-01-02 00:00:00','01','2023',''],
    [3,'01/16/2023','01','2023',''],
    [4,'01/17/2023','01','2023',''],
    [5,'01/16/2023','01','2023',''],
    [6,'02/13/2023','02','2023',''],
    [7,'02/13/2023','02','2023',''],
    [8,'02/13/2023','02','2023',''],
    [9,'26/11/2018','11','2018',''],
    [10,'26/11/2018','11','2018',''],
    [11,'26/11/2018','11','2018',''],
    [12,'26/11/2018','11','2018',''],
    [13,'05/11/2018','11','2018',''],
    [14,'09/11/2018','11','2018',''],

    ],
    columns=['Number','Date','Code','year','Same_Month'])

    df


    so the expected result is that all of them are yes except entries number (4,13,14)

    Continue reading...

Compartilhe esta Página