I have developed a function that was on its own in a script. I ran that script to place the function in my namespace. The line of code I have that was working fine is:
df.my_variable.replace([inf, -inf, nan, NaN], 0, inplace=True)
I have now moved this function into mymodule.py
. I then try to run it:
import mymodule as mm
mm.myfun()
The line of code to replace inf
, etc., now throws the following error:
global name 'inf' is not defined
I'm sure this is a legacy of developing interactively in IPython, but I'm stumped as to how I would define inf
to make this work.
Python Nameerror name is not defined You will encounter a nameerror ( name is not defined) when a variable is not defined in the local or global scope. Or you used a function that wasn't defined anywhere in your program. For example, you will see this error if you try to print a variable that wasn't defined.
The Python "NameError: name is not defined" occurs when we try to access a variable or function that is not defined or before it is defined. To solve the error, make sure you haven't misspelled the variable's name and access it after it has been declared.
Try this:
from numpy import inf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With