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
2,817 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,560 points
0 votes
key error. I love python
answered Feb 18 by anonymous
can you describe the error and help me with the code you are using so that I can help you!

Related Questions In Data Analytics

0 votes
1 answer
0 votes
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 32,260 points
168 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,060 points

edited Apr 12, 2018 by nirvana 4,088 views
0 votes
2 answers

How to remove rows with missing values (NAs) in a data frame?

Hi, The below code returns rows without ...READ MORE

answered Aug 20 in Data Analytics by anonymous
• 32,260 points
6,146 views
0 votes
1 answer

How to rename columns in pandas (Python)?

It is easy by just adding ".columns" ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points
157 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is size includes NaN ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points
777 views
0 votes
7 answers
0 votes
1 answer

Changing Pandas data-frame to JSON type

abc.to_json(orient='records') This command will give you the desired ...READ MORE

answered May 22, 2018 in Data Analytics by anonymous
109 views
0 votes
1 answer

Applying the same function to every row of a data.frame - R

You can use the 'appply()' function for ...READ MORE

answered May 22, 2018 in Data Analytics by Bharani
• 4,560 points
115 views
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,560 points
1,818 views