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] Creating a new column to find the range of date

Discussão em 'Python' iniciado por Stack, Setembro 13, 2024.

  1. Stack

    Stack Membro Participativo

    I am working on a data frame which contains date. I want to create a new column to classify the period of the date in a year. That means that I will assume as every 2 months as a range. But my starting date will be August. Thus,

    Aug to Sep is 1,
    Oct to Nov is 2,
    Dec to Jan is 3,
    Feb to Mar is 4 and
    Apr to May is 5.


    The sample date is as follow:

    data =pd.DataFrame()
    data ['Date'] = ['27-03-2019','08-10-2019','09-04-2019','09-08-2018']
    data.period = pd.to_datetime(data['Date'])


    The expected outcome as range in a new column would be as follows:

    [​IMG]

    How can I do that?

    Continue reading...

Compartilhe esta Página