[Python] Adding a list to a dataframe whilst concating by length of DF

Discussão em 'Python' iniciado por Stack, Abril 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a df as follows :

    ID, Week
    5, 1
    6, 1
    7, 1


    I have a list of reason codes as follows

    ['Work', 'Holiday', 'Sick', 'Jury']


    What I'm trying to do is add this to my current dataframe but multiply this by each unique ID.

    So I would have something like (I'll only use 1 unique ID for brevity),

    ID, Week, Reason
    5, 1, 'Work'
    5, 1, 'Holiday'
    5, 1, 'Sick',
    5, 1, 'Jury'


    I have tried all manner of concats, with varying axes, but I'm none-the-wiser how to approach this.

    Continue reading...

Compartilhe esta Página