Blog
How to Solve Python AttributeError: ‘list’ object has no attribute ‘astype’
This error occurs when you try to call the astype() method on a list as if it were a NumPy ndarray. You can solve this error by converting the list to an array using the numpy.array() method then call the astype() method. For example, import numpy as np lst = [1, 2,...
How to Solve Python NameError: name ‘csv’ is not defined
This error occurs when you try to use the csv module without importing it first. You can solve this error by importing the module using the import keyword. For example, import csv filename = 'fiel.csv' with open(filename, 'r') as csvfile: csvreader =...
How to Solve Python NameError: name ‘datetime’ is not defined
This error occurs when you try to use the datetime module without importing it first. You can solve this error by importing the module. For example, import datetime print(datetime.date.today()) This tutorial will go through how to solve the error with code examples....
How to Solve Python NameError: name ‘time’ is not defined
This error occurs when you try to use the time module without importing it first. You can solve this error by importing the module using the import keyword. For example, import time print(time.gmtime(0)) This tutorial will go through how to solve the error with code...
How to Solve Python NameError: name ‘json’ is not defined
This error occurs when you try to use the json module without importing it first. You can solve this error by importing the module using the import keyword. For example, import json lst = [1, 2, 3] json_str = json.dumps(lst) This tutorial will go through how to solve...
How to Solve Python NameError: name ‘sys’ is not defined
This error occurs when you try to use the sys module without importing it first. You can solve this error by importing the module. For example, import sys print(sys.version) This tutorial will go through how to solve the error with code examples. Table of...
How to Solve Python NameError name ‘np’ is not defined
This error typically occurs when you try to use the NumPy library but do not define the alias np when importing the module. You can solve this error by using the as keyword to alias the numpy module, for example: import numpy as np This tutorial will go through how to...
How to Solve Python NameError: name ‘plt’ is not defined
This error typically occurs when you try to use the state-based interface to Matplotlib called matplotlib.pyplot but do not define the alias plt when importing the API. You can solve this error by using the as keyword to alias the matplotlib.pyplot API, for example:...
How to Solve Python AttributeError: ‘int’ object has no attribute ‘split’
This error occurs if you try to call the split() method on an integer. The split() method belongs to the string class and splits a string using a delimiter returning a list of strings. You can solve this error by checking the type of the object before calling the...
How to Solve Python NameError: name ‘pd’ is not defined
This error typically occurs when you try to use the Pandas library but do not define the alias pd when importing the module. You can solve this error by using the as keyword to alias the pandas module, for example: import pandas as pd This tutorial will go through how...
Suf is a senior advisor in data science with deep expertise in Natural Language Processing, Complex Networks, and Anomaly Detection. Formerly a postdoctoral research fellow, he applied advanced physics techniques to tackle real-world, data-heavy industry challenges. Before that, he was a particle physicist at the ATLAS Experiment of the Large Hadron Collider. Now, he’s focused on bringing more fun and curiosity to the world of science and research online.