How to change/update cell value in Python Pandas dataframe?

+1 vote

I have the following dataframe

  Name Age
0 Mike 23
1 Eric 25
2 Donna 23
3 Will 23

And I want to change the age of Mike. How can I do this?

Apr 8, 2019 in Python by Raj
90,889 views

2 answers to this question.

+1 vote

You can use the at() method to do this

df.at[0,’Age']= 20
answered Apr 8, 2019 by Kunal
when using df.at[row_num, "Col B"] = "yes":

the at() method added a new column in my data frame instead of modifying the
Col B of my dataframe.

Was this the case for anyone else?
Hi @ken, Can you please share your data frame. The syntax of df.at() is correct but probably you aren't using it in accordance with your data frame.
Hey :) I was having the same issue, and using df.iat[] instead of df.at[] worked for me

"df.at[0,’Age']= 20" is not the correction solution

Hi, @There,

Even I have faced the same issue but the above-given solution has worked for me. Could you please share your workaround so that we can analyze why the solution isn't working!
0 votes

Hi,

You can use at() method to update your dataset. I have attached one example for your reference.

import pandas as pd
df1=pd.read_csv('my.csv')
Place State
0 Kolkata WestBengal
1 Delhi Delhi
2 Bangalore Karnataka
3 Kolkata WestBengal
4 Delhi Delhi
df1.at[0,'Place']= 'Mumbai'
Place State
0 Mumbai WestBengal
1 Delhi Delhi
2 Bangalore Karnataka
3 Kolkata WestBengal
4 Delhi Delhi

I hope this will help you.

answered Jun 25 by MD
• 81,590 points

Related Questions In Python

0 votes
1 answer

How to get value in Pandas dataframe using index?

You can use the iloc method to do ...READ MORE

answered Apr 8, 2019 in Python by Rohit
1,001 views
0 votes
1 answer

How to check if any value is NaN in a Pandas DataFrame?

Hello @kartik, If you need to know how ...READ MORE

answered Jun 15 in Python by Niroj
• 80,940 points
1,257 views
0 votes
1 answer

How to check if a value exists in pandas dataframe index?

Hello @kartik, Basically instead of raising exception I ...READ MORE

answered Jun 15 in Python by Niroj
• 80,940 points
1,890 views
0 votes
1 answer

How to change data types in Pandas DataFrame?

Hi@akhtar, You can use astype function to change ...READ MORE

answered Jun 22 in Python by MD
• 81,590 points
172 views
0 votes
1 answer

How to rename columns in pandas (Python)?

You can use the rename function in ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8 by MD 530 views
0 votes
1 answer

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

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8 by Gitika 1,266 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
7,339 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,580 points
3,301 views
0 votes
1 answer

How to convert a Pandas GroupBy object to DataFrame in Python

g1 here is a DataFrame. It has a hierarchical index, ...READ MORE

answered Nov 12, 2018 in Python by Nymeria
• 3,520 points
23,680 views
0 votes
1 answer

How to find if a value exists in Pandas dataframe?

Try this:​ for name in df['Name']: ...READ MORE

answered Apr 8, 2019 in Python by Tina
8,805 views