AttributeError: 'function' object has no attribute 'isna' - python-3.x

After applying isna to my original dataset, and saving it to a new variable.
That new variable is not acting like a dataframe and the output shows this error (AttributeError: 'function' object has no attribute 'isna') when I look for its shape.
When I read the new dataframe, it gives the description of the new dataframe in the output.
df1Books = df1.dropna
print(df1Books)
It is giving description of the new variable df1Books
And
df1Books.head()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-20-8f073fd0d9cc> in <module>
----> 1 df1Books.head()-tt
AttributeError: 'function' object has no attribute 'head'

Related

AttributeError: 'int' object has no attribute 'count' in dictionary

my question is that i am trying to get dictionary done in google colab but it is getting error of AttributeError: 'int' object has no attribute 'count' in dictionary again and again.
temp_dict = {"33": [temperatures.count(33)],"34": [temperatures.count(34)],"39": [temperatures.count(39)], "40": [temperatures.count(40)], "42": [temperatures.count(42)],"29": [temperatures.count(29)]}
this is my code line but it is not able to count in google colab.is there something missing.
From what I'm getting is that variable temperatures is not a list but the int
temperatures = [1,2,3,3,4]
print(temperatures.count(1)) # Returns 1
print(temperatures.count(3)) # Returns 2
print(temperatures.count(5)) # Returns 0
# Possible your code
temperatures = 33
print(temperatures.count(33)) # Returns error: AttributeError: 'int' object has no attribute 'count'
If you have python 3.11, it will highlight in which part your code error was made, for example
Traceback (most recent call last):
File "c:\Users\******\Desktop\nf\a.py", line 2, in <module>
print(temperatures.count(33))
^^^^^^^^^^^^^^^^^^
AttributeError: 'int' object has no attribute 'count'

Class assignment: object not callable [duplicate]

As a starting developer in Python I've seen this error message many times appearing in my console but I don't fully understand what does it means.
Could anyone tell me, in a general way, what kind of action produces this error?
That error occurs when you try to call, with (), an object that is not callable.
A callable object can be a function or a class (that implements __call__ method). According to Python Docs:
object.__call__(self[, args...]): Called when the instance is “called” as a function
For example:
x = 1
print x()
x is not a callable object, but you are trying to call it as if it were it. This example produces the error:
TypeError: 'int' object is not callable
For better understaing of what is a callable object read this answer in another SO post.
The other answers detail the reason for the error. A possible cause (to check) may be your class has a variable and method with the same name, which you then call. Python accesses the variable as a callable - with ().
e.g. Class A defines self.a and self.a():
>>> class A:
... def __init__(self, val):
... self.a = val
... def a(self):
... return self.a
...
>>> my_a = A(12)
>>> val = my_a.a()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>>
The action occurs when you attempt to call an object which is not a function, as with (). For instance, this will produce the error:
>>> a = 5
>>> a()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
Class instances can also be called if they define a method __call__
One common mistake that causes this error is trying to look up a list or dictionary element, but using parentheses instead of square brackets, i.e. (0) instead of [0]
The exception is raised when you try to call not callable object. Callable objects are (functions, methods, objects with __call__)
>>> f = 1
>>> callable(f)
False
>>> f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
I came across this error message through a silly mistake. A classic example of Python giving you plenty of room to make a fool of yourself. Observe:
class DOH(object):
def __init__(self, property=None):
self.property=property
def property():
return property
x = DOH(1)
print(x.property())
Results
$ python3 t.py
Traceback (most recent call last):
File "t.py", line 9, in <module>
print(x.property())
TypeError: 'int' object is not callable
The problem here of course is that the function is overwritten with a property.

Why am I getting AttributeError: 'Series' object has no attribute 'to_datetime' and AttributeError: 'Series' object has no attribute 'concat'

DATA SET HERE https://drive.google.com/open?id=1r24rrKWcIpA1x34tPY8olJFMtjzl0IRn
I am trying to convert my time series into type DateTime, so to do that I needed to make all the number eg.(1256,430,7) into same size eg.(1256,0430,0007) for the to_datetime() to work.
So fist I separated the Entity according to their length and added number of zero required, concat the "Series" into one that were seperated.
FIRST ERROR
This error was sorted by using append() in Series. Then I tried to_datetime()
Second Error
I cant figure out what am I doing wrong
I updated my pandas library up to date.
Still the problem remains.
I tried this on Google Colab thinking might be some problem in my pandas lib.
a='0'+arr_time[arr_time.astype(str).str.len()==3].astype(int).astype(str)
b='0'+dep_time[dep_time.astype(str).str.len()==3].astype(int).astype(str)
c='00'+arr_time[arr_time.astype(str).str.len()==2].astype(int).astype(str)
d='00'+dep_time[dep_time.astype(str).str.len()==2].astype(int).astype(str)
e='000'+arr_time[arr_time.astype(str).str.len()==1].astype(int).astype(str)
f='000'+dep_time[dep_time.astype(str).str.len()==1].astype(int).astype(str)
g=arr_time[arr_time.astype(str).str.len()==4].astype(int).astype(str)
h=dep_time[dep_time.astype(str).str.len()==4].astype(int).astype(str)
arr_time=pd.concat([a,c,e,g])
dep_time=pd.concat([b,d,f,h])
'''concat() is then replaced by append() ERROR detail is below
{AttributeError Traceback (most recent call
last)
<ipython-input-20-61e7a2e98b70> in <module>()
----> 1 arr_time=pd.concat([aa,ba,ca,pa])
2 dep_time=pd.concat([ad,bd,cd,pa])
/usr/local/lib/python3.6/dist-packages/pandas/core/generic.py in
__getattr__(self, name)
5065 if
self._info_axis._can_hold_identifiers_and_holds_name(name):
5066 return self[name]
-> 5067 return object.__getattribute__(self, name)
5068
5069 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'concat'}'''
arr_time=a.append(c).append(e).append(g)
dep_time=b.append(d).append(f).append(h)
datetime=arr_time.to_datetime(format="%H%M")
'''second error BOTH OF THEM LOOK ALIKE
{AttributeError Traceback (most recent call last)
<ipython-input-13-5a63dad5c284> in <module>
----> 1 datetime=arr_time.to_datetime(format="%H%M")
~\AppData\Local\Continuum\anaconda3\lib\site- packages\pandas\core\generic.py in __getattr__(self, name)
5065 if
self._info_axis._can_hold_identifiers_and_holds_name(name):
5066 return self[name]
-> 5067 return object.__getattribute__(self, name)
5068
5069 def __setattr__(self, name, value):
AttributeError: 'Series' object has no attribute 'to_datetime'}'''

Python3.x: TypeError: 'StringVar' object is not iterable & AttributeError: 'StringVar' object has no attribute 'items'

when I try this,
archivist_dates=[
"Thur,19th of October",
"Fri,20th of October",
"Sat,21th of October",
"Sun,22th of October",
"Mon,23th of October",
"Tue,24th of October",
"Wed,25th of October",
"Latest"]# the list of dates to be selected by the users
variable=StringVar()
variable.set(archivist_dates[0])
list_menu=OptionMenu(archivist_gui,variable,*archivist_dates)
list_menu.grid(row=2,column=2)
archivist_buttons=Frame(archivist_gui)
extract_button=Radiobutton(archivist_buttons,variable,text='Extract news
from archive', value=1, font=('Times',24),command=extracts)
display_button=Radiobutton(archivist_buttons,variable,text='Display news
extracted',value=2,font=('Times',24),command=htmlgenerator)
archive_button=Radiobutton(archivist_buttons,variable,text='Archive the
latest news',value=3,font=('Tikmes',24),command=download)
There was an error statement showed up as following:
_cnfmerge: fallback due to: 'StringVar' object is not iterable Traceback (most recent call last): File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py",
line 103, in _cnfmerge
cnf.update(c) TypeError: 'StringVar' object is not iterable
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File
"/Volumes/study/en01/ifb104/ass2/InternetArchive/news_archivist.py",
line 798, in
extract_button=Radiobutton(archivist_buttons,variable,text='Extract
news from archive', value=1, font=('Times',24),command=extracts)
File
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py",
line 2978, in init
Widget.init(self, master, 'radiobutton', cnf, kw) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py",
line 2284, in init
cnf = _cnfmerge((cnf, kw)) File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py",
line 106, in _cnfmerge
for k, v in c.items(): AttributeError: 'StringVar' object has no attribute 'items'
Can someone explains the error and gives me a hand to fix it?
The problem is here:
extract_button=Radiobutton(archivist_buttons,variable,text='Extract news from archive', value=1, font=('Times',24),command=extracts)
You're assigning variable incorrectly, the Radiobutton is looking for variable['items'] which doesn't exist because StringVar() doesn't have an attribute called 'items'.
Instead you should assign your StringVar() as variable=variable. Meaning the full call would be:
extract_button=Radiobutton(archivist_buttons,variable=variable,text='Extract news from archive', value=1, font=('Times',24),command=extracts)

Itertuples() in Tkinter function reveals an AttributeError: 'tuple' object has no attribute 'A'

Within a Tkinter function, I need to create the list named: 'value' extracting every 10 rows the value of dataframe column named: df['A'].
The following for-loop works perfectly out of a Tkinter function:
value = []; i = 0
for row in df.itertuples():
i = 1 + i
if i == 10:
value_app = row.A
value.append(value_app)
i=0
However within Tkinter function I have the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/anaconda/lib/python3.6/tkinter/__init__.py", line 1699, in __call__
return self.func(*args)
File "<ipython-input-1-38aed24ba6fc>", line 4174, in start
dfcx = self.mg(a,b,c,d,e)
File "<ipython-input-1-38aed24ba6fc>", line 4093, in mg
value_app = r.A
AttributeError: 'tuple' object has no attribute 'A'
A similar for-loop structure is running in another part of the same Tkinter function and is executed without errors.
If the column A is your first column you can do :
value_app = row[0]
I had the same problem and I think that it only sees it as regular arrays

Resources