Python: most recent call last error [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Can't understand the error in this as the brackets are as per directions
mean=df["Normalized-losses"].mean()
Traceback (most recent call last):
File "C:\Users\Aarushi Goyal\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\nanops.py", line 822, in _ensure_numeric
x = float(x)
Please provide solution

Try converting the column into numeric using
pd.to_numeric(df['Normalized-losses'], errors = 'coerce')
Then try:
mean = df['Normalized-losses'].mean()
You can also use:
mean = df.loc[:, 'Normalized-losses'].mean()
If it doesn't help do provide more info regarding the error.

I think the variable "Normalized-losses" would be a non-numerical type variable.
Try pandas dtypes method to check data type:
df.dtypes
If its non-numerical then use astype() method to change the data type.

Related

Python NameError: name ' ' is not defined [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
i am inputting simple code into IDLE but it keeps telling me after I run the simple program that a word to check how many vowels is not defined.
def search4vowels(word):
'''Return a boolean bassed on any vowels found.'''
vowels = set('aeiou')
return vowels.intersection(set(word))
Error Message
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
gal
NameError: name '' is not defined
I think you call your function like this:
search4vowels(gal).
Try calling it like this: search4vowels("gal").
You have to enclose strings in quotes, otherwise python is looking for a variable called gal (In your example).
gal is not defined==>Error

what is my mistake in the code and why is that error for? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
So basically I have to write a code which tells the user to input numbers (as variables I named them number1, number2, number3 ...) until I get the answer of zero once you add each number that they inputted then which the sum is equal to zero I should print how many numbers they inputted so the answer they got was zero, now the main thing is that I know how to write that code but there is an error that I get:
Traceback (most recent call last):
File "Solution.py", line 13, in <module>
sys.exit()
NameError: name 'sys' is not defined
Maybe try using
from sys import *
and just use exit(0) when you want to sys.exit()

AttributeError: 'str' object has no attribute '__name__' [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
What is causing this error? Isn't it possible commenting out lines like this inside code?
for i in (Class_1, """Class_2, Class_3"""):
name = i.__name__
Class_1, Class_2 and Class_3 are classes declared before the upper code.
Error output:
> Traceback (most recent call last):
File "", line 2, in <module>
name = i.__name__
AttributeError: 'str' object has no attribute '__name__'
Process finished with exit code 1
Error message line edited to fit the example code
Remove the triple-quoted string """Class_2, Class_3""" to avoid iterating over it which is what you're doing in this case so it looks like for i in (Class_1,) (parenthesis are optional).
It seems you want to comment out those unnecessary sides, but please note that those triple-quotes strings technically aren't comments, so they can still affect the script in some areas you didn't intend.
What do you mean by
for i in (Class_1, """Class_2, Class_3"""):
When you iterate over this tuple, the second element is a string, thus causing the error.

Why will this function not open my file? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
def open_file(filename):
file_open= open(filename,"r")
return file_open
When I try and call the function I get the following results:
>>> open_file(random.txt)
Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
open_file(random.txt)
NameError: name 'random' is not defined
try
open_file('random.txt')
Strings in Python need to be quoted.
random is being interpreted as an object, and is undefined.
You forgot quotes:
open_file('random.txt')
python thinks random is an object, which obviously you didn't define. The quotes make it a string.
you just need to input the filename as a string; here's how it must be done:
>>> open_file('random.txt')
note that your function works just fine, all you need to do is call it properly.

Python, TypeError: list indices must be integers, not str [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm trying to compare two list of lists if they are equal.
if grafo.node[va,vb] == grafo.node[va,vb]:
I get this error:
Traceback (most recent call last):
File "C:/Python33/Archive/PythonGrafos/Alpha.py", line 85, in <module>
menugrafos()
File "C:/Python33/Archive/PythonGrafos/Alpha.py", line 55, in menugrafos
Beta.criararesta(grafo,va,vb)
File "C:/Python33/Archive/PythonGrafos\Beta.py", line 29, in criararesta
if grafo.node[va,vb] == grafo.node[va,vb]:
TypeError: list indices must be integers, not tuple
I'm inserting integers in the lists. What does this error mean?
The error suggests that va and vb are strings, so you cannot use them as indexes. If they contain some integer you want to use for index, then use [int(va)][int(vb)] and it will probably work.
Also interjay is right your code is different than the traceback!
What is in va and vb? It needs to be an int, assuming that node is a list. If you do want it to use a string, as an index, use a dict instead.
What you probably want to do is:
grafo.node[int(va)] == grafo.node[int(vb)]

Categories