0

I have a pandas dataframe that consists of unique item_ids as the following:

    item_id
0   123467
1   456789
2   546543
3   876641

I want to generate a date column in the dataframe, that would contain dates from 1st january,2021 to 30th december,2021 for each unique rows. I want to have something like this:

    item_id  date
0   123467   2021-01-01
1   123467   2021-01-02
2   123467   2021-01-03
3   123467   2021-01-04
...

Can you suggest me a way to get this working?

  • Check out this one it might help. https://stackoverflow.com/questions/43526973/pandas-create-new-date-rows-and-forward-fill-column-values – Sushil Kumar Jan 10 '22 at 05:49

1 Answers1

1
import pandas as pd
data = pd.date_range('1/1/2021', periods = 365, freq ='d')
 
print(data)

you can append the output of this to your dataframe as new column

MD5
  • 1,356
  • 15
  • 14