NameError name pandas is not defined, How To Fix
Pandas NameError resolution and aliases
Pandas NameError is frustrating. This error happens because your python script cannot find the name βpandasβ in your namespace. This means you have either imported pandas under a different name or not at all.
How to Fix:
- Go to the top of your script and make sure you actually imported pandas
- If you have, make sure you understand which alias youβre using. In this case
import pandas as pd
βpdβ is known as the alias.
Pseudo code: import pandas under the correct name
Pandas NameError
In most cases, my guess is that you havenβt imported pandas to your python script. This is a simple mistake and has a simple answer, head to the top of your script and import it.
If this isnβt the case, then you likely imported it under a different alias that youβre not using
Pandas Aliases
When you import python packages, you have the option to specify an alias. As alias is an alternative string (usually a shorter string) that will be used in place of the default name of your package.
This is usually done as a shortcut to not type as many letters. For example pandas is usually referred to as βpdβ, numpy as βnpβ, matplotlib.pyplot as βpltβ and so forth.
Letβs look at a code example of how to fix this.