'DataFrame' object has no attribute 'get_value' in Pandas

Viewed 27777

Just learning python now, have very weak programming background.

I keep getting the error: 'DataFrame' object has no attribute 'get_value' using python 3.8. The file is a random file I downloaded from the internet just to learn how to use dataframes and pandas. The object here is to pull a specific value out of the dataframe, so that I can manipulate it later.

import pandas as pd

pb_list = [] pb_list =
pd.read_csv(r"PB2010plus.csv") print(pb_list)
print(type(pb_list))

print(pb_list.get_value(1047, 'Winning Numbers'))

here's the error line

Traceback (most recent call last): File "I:/Python/PycharmProjects/Learning Python 1/probabilityfunsheet.py", line 8, in print(pb_list.get_value(1047, 1)) File "C:\Users\greyb\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\core\generic.py", line 5274, in getattr return object.getattribute(self, name) AttributeError: 'DataFrame' object has no attribute 'get_value'

I am using pycharm, and did some searching, came across https://www.geeksforgeeks.org/python-pandas-dataframe-get_value/ which is where I got the idea as a potential solution for my 'problem'.

5 Answers

Starting it with an underscore worked for me

df._get_value(index,'name')

A good habit while reading data frames in Python is setting them as a variable:

import pandas as pd

pb_list = pd.read_csv("PB2010plus.csv") 

Thus, to visualize them you won't need to print them, but you will just need to recall the variable pb_list.

# take a look to the dataframe
pb_list

# check the dataframe's type 
type(pb_list)

# access to 1047 row index inside the Winning Numbers column
pb_list.get_value(1047, 'Winning Numbers') 

However get_value has been deprecated and will be removed in a future release. Please use .at[] or .iat[] accessors instead.

Regarding your question. If you want to store the value that you are searching for in a variable to manipulate it in the future, here's the code:

# storing the desired value in target_value
target_value = pb_list.get_value(1047, 'Winning Numbers')

Please try using

df._get_value()

instead of

df.get_value()

The get_values method for a DataFrame was deprecated. Use values() instead. More info here

You don't need to put the result into a list pd_list = [] This code will give you an empty list and fill out this list with for loop in general. Try to remove that code and see what happens. Hope this helps.

Related