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,700 points
858 views

2 answers to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,550 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
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
60 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 1,532 views
0 votes
1 answer

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

You can use complete.cases in the following ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,140 points
3,334 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,700 points
63 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,700 points
600 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
59 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,550 points
28 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,550 points
824 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.