Rauan Saturin
Rauan Saturin

Reputation: 61

Replacing the values of a particular number of columns with zeroes

I have a dataframe with 9 columns. I need to replace all values of columns 3-9 with zeroes and leave the values in other columns as they are. Any ideas?

Upvotes: 0

Views: 19

Answers (1)

Vaibhav Khandelwal
Vaibhav Khandelwal

Reputation: 153

you can simply use iloc which has following syntax:

dataframe_name.iloc[rows, columns]

As you want to replace all values of columns 3-9 with zeroes and leave the values in other columns as they are:

dataframe_name.iloc[: , 3:10] = 0

Here we have used slicing. for rows I have used ':' which means all the rows and for the columns I have used '3:10' which means all the columns from index 3 to 9 both inclusive

Upvotes: 1

Related Questions