'Panda dataframe replace() method for row numbers

I need to replace some values in a column with a specific value using the row numbers list of the required values as an array like following array.Can I use dataframe.replace() for that?

row_numbers = [  4,   7,  15,  18,  49,  60,  78,  80]


Solution 1:[1]

You can use loc

df.loc[row_numbers, 'col'] = 3

in case your index is not number

df['col'].iloc[row_numbers] = 3

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ynjxsjmh