I have a dataframe like this:
article_id title NaN title_1 NaN title_2 NaN title_3 '202102011404103' title_4 '202102011404104' title_5 NaN title_6 Firstly I would like to add a condition 'if there is NaN value do the following' (else do nothing). If there is NaN value in the column: I would like to add directly an incremental value to NaN values in the column with something like this:
x = 1 df.insert(0, 'article_id', range(x, x + len(df))) But I don't know how to add directly the code above to the column article_id, only to NaN values. How can I do it ?
Expected output:
article_id title 1 title_1 2 title_2 3 title_3 '202102011404103' title_4 '202102011404104' title_5 4 title_6