nameerror name pd is not defined Error

nameerror name pd is not defined Error : Remove it Easily

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)
Not properly imported pandas module error
Not properly imported pandas module error

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.

Not properly imported pandas module after removing error

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.

Not properly imported pandas module error in Jupyter NotebookNot properly imported pandas module error in Jupyter Notebook
Not properly imported pandas module error in Jupyter Notebook

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.

Not properly imported pandas module after removing error in Jupyter Notebook
Not properly imported pandas module after removing error in Jupyter Notebook

You can see you are now not getting any error.

Conclusion

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.

Thanks

Data Science Learner Team

Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.

Thank you for signup. A Confirmation Email has been sent to your Email Address.

Something went wrong.

 
Thank you For sharing.We appreciate your support. Don't Forget to LIKE and FOLLOW our SITE to keep UPDATED with Data Science Learner