Nameerror name pd is not defined
How to fix the Python nameerror name pd is not defined error message? In this article, we will show you how you can resolve this error. Aside from that, this …
itsourcecode.com hosts 49+ documented fixes for Python NameError messages: the error class raised when Python encounters a name (variable, function, class, or module reference) that isn’t defined in the current scope. Most NameErrors trace to missing imports (np, pd, keras), Python 2 → 3 migration leftovers (raw_input, unicode), or Jupyter-only builtins running outside a notebook (display, get_ipython). Browse the fixes below by category.
What is a Python NameError?
A NameError is raised when Python tries to use a name that hasn’t been defined yet in the local, enclosing, or global scope. The error message always names the missing identifier in quotes, for example NameError: name 'np' is not defined means you wrote np.array(...) but never did import numpy as np. NameError is a sibling of UnboundLocalError (variable defined later in function) and a subclass of Exception.
How to fix any NameError in 4 steps
Read the missing name in quotes. The error tells you exactly which identifier is undefined.
Check if you imported it. If the name is np, pd, plt, tf, nn, or any library alias, you almost certainly need an import library as alias line at the top of the file.
Check spelling and case. Python is case-sensitive. True ≠ true. List ≠ list. A typo IS a NameError.
Check the scope. A variable defined inside a function isn’t visible outside it. A name defined in a Jupyter cell that hasn’t run yet doesn’t exist. A name in another module needs to be imported, not just typed.
Featured NameError fixes by category
📊 Library imports (numpy, pandas, matplotlib, sklearn)
The most common NameError, you used a library alias but forgot the import.
name ‘np’ is not defined (numpy)
name ‘pd’ is not defined (pandas)
name ‘keras’ is not defined
name ‘model’ is not defined
name ‘spark’ is not defined (PySpark)
name ‘sqlcontext’ is not defined (PySpark SQL)
🐍 Python built-ins and stdlib
name ‘os’ is not defined
name ‘sys’ is not defined
name ‘time’ is not defined
name ‘random’ is not defined
name ‘timedelta’ is not defined (datetime)
name ‘open’ is not defined
name ‘list’ is not defined
name ‘base’ is not defined
📓 Jupyter / IPython-only names
Names that exist inside Jupyter notebooks but raise NameError when you copy the code to a regular .py script.
name ‘display’ is not defined (IPython display)
name ‘get_ipython’ is not defined
name ‘__file__’ is not defined (Jupyter / REPL)
🔁 Python 2 → 3 migration
Names that existed in Python 2 but were removed or renamed in Python 3.
name ‘raw_input’ is not defined (use input())
name ‘unicode’ is not defined (Python 3 uses str)
🔣 Scope and self-reference
name ‘self’ is not defined (method vs function)
name ‘kwargs’ is not defined
name ‘_C’ is not defined (PyTorch internal)
name ‘x_train’ is not defined (ML notebook scope)
name ‘X’ is not defined
2026 Updated Guides
Name ‘model’ is not defined: ML notebook scope issues
Name ‘spark’ is not defined: PySpark session setup
Name ‘list’ is not defined: built-in shadowing
Name ‘__file__’ is not defined: Jupyter/REPL context
Related error categories
NameError is one of 10 hubs in our Python & JavaScript error reference cluster, 980+ documented fixes total. If your error isn’t a NameError, jump to the right hub below:
TypeError Reference, 220+ Python & JS TypeError fixes
ModuleNotFoundError Reference, 198+ Python import errors
AttributeError Reference, 173+ “object has no attribute X” fixes
ValueError Reference, 100+ pandas/NumPy/sklearn fixes
ImportError Reference, 67+ “cannot import name X from Y” fixes
RuntimeError Reference, 49+ PyTorch/CUDA/async runtime errors
SyntaxError Reference, 48+ Python & JavaScript syntax errors
ReferenceError Reference, 34+ JavaScript “is not defined” fixes
HTTP Error Reference, 35+ HTTP status code fixes (4xx, 5xx)
Python Tutorial, beginner-to-intermediate Python lessons
About this NameError reference
This NameError reference has been built since 2015 by PIES Information Technology Solutions in Binalbagan, Negros Occidental, Philippines. Every post comes from a real error encountered in production code. Used by 12,000+ Python developers monthly across the Philippines, India, the United States, and beyond.
How to fix the Python nameerror name pd is not defined error message? In this article, we will show you how you can resolve this error. Aside from that, this …
Tired of figuring out the solution for the Python nameerror: name unicode is not defined error message? Well, this article got your back. Want to know why? In this article, …
Today, we’ll explore the Python nameerror: name os is not defined error message. If you are struggling because you don’t know how to fix it? Then keep on reading! In …
How to resolve the Python “nameerror: name self is not defined” error message? We know that errors are inevitable that programmers or developers usually experience. If you’re having a hard time dealing …
In this article, we will hand you the solutions for Python’s “nameerror: name random is not defined” error message. This error message is common in Python programming, and it is easy …
Are you stuck on this “nameerror: name ‘webdriver’ is not defined” error message? Keep reading as we will walk you through the process to resolve this error. This article discusses …
You wrote your very first Python script, hit Run, and instead of a result you got this scary red text: NameError: name ‘something’ is not defined. Don’t worry, every single …
The “nameerror: name _mysql is not defined” is an error message raised when working with the mysql in Python. If you are facing this error and don’t know how to …
Today, we will explore the solutions for nameerror: name glpushmatrix is not defined error message in Python. So, if you’re dealing with this error right now, keep reading. It is …
How to fix the nameerror: name nltk is not defined error message in Python? This error is raised when you are using the Natural Language Toolkit (NLTK) in your Python …