Pandas is a python module used mostly in data analytics and manipulation. Most of the newcomers and experienced programmers make a minor mistakes. That’s nameerror name pd is not defined of error comes. Here “pd” is pandas module imported as alias pd module.
In this entire article, We will look at the mistakes done by the coders or programmers they do it often.
Mistake 1: Not imported pandas module.
This mistake comes when the programmers uses pd in their entire code section. But they not imported it properly. Even the IDE also show red color underline. For example , I have to read a CSVs file and print it then I will write the following code you will get the nameerror name pd is not defined error.
data = pd.read_csv("cars.csv) print(data.head)
How to solve it?
The solution to this mistake is very simple. Just write import pandas as pd before any code section that are using pd. Make sure you have already installed pandas.
Mistake 2: Forget to run Cell in Juypter Notebook
If you are using the Jupyter notebook for the execution of your code. Then coders make a minor mistake. That is they write import pandas as pd in one cell and write the remaining program in other cells. Then, they forget to run the one cell with the import statement and run the other cell.
Let’s run the same example as the above.
How to solve this issue?
To solve this issue you have to just run the cell first that has import pandas as pd statement. Then run the other cell. It will clearly remove the nameerror name pd is not defined error.
You can see you are now not getting any error.
These are mistakes that coders generally faced. Even if you are receiving an error after all the solutions then there must be installation error. Try to install pandas again after removing or uninstalling the panda module. It will definitely solve the nameerror name pd is not defined error.
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.