+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 115,430 views

## 3 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!

Hi,

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

import pandas as pd
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

answered Jun 25, 2020 by
• 95,180 points

Use iloc:

df.iloc[2,3] = 32

print(df)
#   A1  B1  C1  D1
#0   0   0   0   0
#1   0   0   0   0
#2   0   0   0  32
#3   0   0   0   0

Or if you want to modify by index and column name, use loc:

df.loc[2, 'D1'] = 32
answered Dec 9, 2020 by anonymous
• 82,720 points

## How to set value for particular cell in pandas DataFrame using index?

Why df.xs('C')['x']=10 does not work: df.xs('C') by default, returns a new ...READ MORE

## How to get value in Pandas dataframe using index?

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

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

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

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

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

## How to rename columns in pandas (Python)?

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

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

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

## Replacing a row in pandas data.frame

key error. I love python READ MORE

## Converting a pandas data-frame to a dictionary

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