Replacing a row in pandas data frame

0 votes

I am working with this data-frame:

print(abc)
    cyl mpg
0    4  21.0
1    6  21.0
2    4  22.8
3    4  21.4
4    8  18.7
5    4  18.1

I would want to replace the values of the fourth row with -> cyl:6,mpg:19.4

May 23, 2018 in Data Analytics by DeepCoder786
• 1,720 points
13,317 views

2 answers to this question.

0 votes
abc.loc[3]=[6,19.4]

This command takes in the index of the row, where the values are to be replaced. Since the index of 4th row is 3, we'll assign abc.loc[3]=[6,19.4]

This gives us the desired result:

print(abc)
    cyl  mpg
0    4  21.0
1    6  21.0
2    4  22.8
3    6  19.5
4    8  18.7
5    4  18.1
answered May 23, 2018 by Bharani
• 4,660 points
0 votes
key error. I love python
answered Feb 18, 2019 by anonymous
can you describe the error and help me with the code you are using so that I can help you!