[Python] How to do padding in pandas

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

  1. Stack

    Stack Membro Participativo

    I have a dataset contain of URLs. and after URLs I have related information. I'm going to use deeplearning algorithm to train and test the model. I have an issue of length. Now I want to calculate which has a lot of data and then after that if the data is less than that amount pad it with 0 instead of url1_data or url2_data. But if the same url come in the middle of two different url drop that url. I have no code to post because I don't know how to do it.

    col1 col2 col3
    1 2 url1
    1 2 url1_data
    1 2 url1_data
    1 2 url1
    1 2 url1_data
    1 2 url1_data
    1 2 url2
    1 2 url2_data
    1 2 url2_data


    Expected output::

    col1 col2 col3
    1 2 url1
    1 2 url1_data
    1 2 url1_data
    1 2 url1_data
    1 2 url1_data
    1 2 url2
    1 2 url2_data
    1 2 url2_data
    1 2 url2_data(0) # 0 padded
    1 2 url2_data(0) # 0 padded


    length is equal now and the repeated URL is also removed

    and a lot of data mean number of rows related to that url. like for url1 I have 4 rows url1_data which is more data than url2 data(rows) so I add two extra rows below url2. so now the data are same. suppose we have url3 having three rows which is less than url1 so I need to add only one url3_data(0) mean this is padded value

    Continue reading...

Compartilhe esta Página