AttributeError: ‘dataframe’ object has no attribute ‘set_value’ ( Solved )

AttributeError_ 'dataframe' object has no attribute 'set_value' ( Solved )

Pandas allow you to convert the datasets to the dataframe. Suppose you want to change the value of the specific row in a specific column. If you will try to change the value using the set_value() method then you will get the error AttributeError: ‘dataframe’ object has no attribute ‘set_value’. In this tutorial, you will learn how to solve this attributeerror.

Why AttributeError: ‘dataframe’ object has no attribute ‘set_value’ Occurs?

The root cause for getting this error is that you must be using the older version of the pandas package. The set_value() method has been depreciated since the 0.21 pandas version. Instead of it, I will tell the other function to change the value.

You will get the ‘dataframe’ object has no attribute ‘set_value’ error when you will run the below lines of code.

import pandas as pd
import numpy as np
data = {"name":["Rob","Bam","Maya","Rob"],"age":[23,25,26,23],
        "country":["USA","UK","France","USA"]}
df = pd.DataFrame(data)
df.set_value(2,"age",30)
df

Output

'DataFrame' object has no attribute 'set_value'
‘DataFrame’ object has no attribute ‘set_value’

You can see I am trying to change the value of the age column at position 2 to 30 but I am getting an error.

The solution of ‘dataframe’ object has no attribute ‘set_value’ error

The solution to this error is that you have to not use the set_value() function. Instead, use them at[] method to change the value of the rows at a particular location. Taking the same example I will use the following lines of code to change the value of that 2nd row for the “age” column to 30.

import pandas as pd
import numpy as np
data = {"name":["Rob","Bam","Maya","Rob"],"age":[23,25,26,23],
        "country":["USA","UK","France","USA"]}
df = pd.DataFrame(data)
df.at[2,"age"]=30
df

Output

Changing the second row value to 30 for column name age
Changing the second row value to 30 for column name age

Conclusion

If you want to change the value of the specific row for the column then don’t use the set_value() method if the version of the pandas is the newest.  Instead, use at[] to change the value. The above solution will solve the error ‘dataframe’ object has no attribute ‘set_value‘.

I hope you have liked this tutorial. If you are still getting errors then contact us for more help.

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

Meet Sukesh ( Chief Editor ), a passionate and skilled Python programmer with a deep fascination for data science, NumPy, and Pandas. His journey in the world of coding began as a curious explorer and has evolved into a seasoned data enthusiast.
Share via
 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner