I have a dataframe that looks like this:
article_id title
NaN title_1
NaN title_2
NaN title_3
'202102011404103' title_4
'202102011404104' title_5
NaN title_6
I would like to apply something like this code, to NaN values in article_id column:
from datetime import datetime
date = datetime.strftime(datetime.now(), "%Y%m%d%H%M")
df['article_id'] = [int(date + str("0"*(3-len(str(i)))) + str(i)) + 1 for i, k in df.reset_index().iterrows()]
Instead of `datetime.now() I would like to start the 1st january. I would like to have a value for the variable date = '202101011348' for example
And in final result I would like to have the same length as row 4 and 5 for article_id column and start to a precise date (202101011348)
I tought doing this:
df[df['article_id'].isna()]
And then apply the code above.
Expected output:
article_id title
'202101011404106' title_1
'202101011404107' title_2
'202101011404108' title_3
'202102011404103' title_4
'202102011404104' title_5
'202101011404109' title_6
But how to apply this directly to the df, only to NaN values in the article_id column ?