What’s the Best NumPy Book?

Fear of missing out in data science? Data science and machine learning are taking over. Data-driven decision making penetrates every single company nowadays. Data science is indeed the “sexiest job in the 21st century“! There is one Python library which is the basis of any data science related computation you can undertake as a Python … Read more

How to Get a Windows Screenshot in Python?

Problem Formulation Say, you run a Python program on your Windows machine and you want it to take a screenshot. How to accomplish this programmatically? Method 1: Multiple Screen Shots Module To programmatically record one or more screenshots in your Python program, run the sct.shot() function from the mss module. Install the Multiple Screen Shots … Read more

[Solved] AttributeError: can’t set attribute in python

Problem Formulation You create a namedtuple object in your code and you want to overwrite one of the attribute values like you’re used to for normal objects: But, unexpectedly, Python raises an AttributeError: can’t set attribute. ? What can you do? ? Let’s understand the reason this error occurs—after that, you’ll learn the best fixes. … Read more

np.nonzero() – A Simple Guide with Video

This article explains first how the NumPy nonzero() function works. It then goes on to apply it to a practical problem on how to find array elements using the nonzero() function in NumPy in a practical data science example. Syntax numpy.nonzero(a) The np.nonzero(arr) function returns the indices of the elements of an array or Python … Read more

How to Change the Figure Size for a Seaborn Plot?

Seaborn is a comprehensive data visualization library used for the plotting of statistical graphs in Python. It provides fine-looking default styles and color schemes for making more attractive statistical plots. Seaborn is built on the top portion of the matplotlib library and is also integrated closely with data structures from pandas.                                                             How to change … Read more

3 Little-Known NumPy Tricks in One Line [Python Puzzle]

Trick #1: Slicing and Slice Assignment This one-liner demonstrates the power of three interesting NumPy features and how their combination can solve a small data science problem in a clean and efficient manner. Say, you are working at a company and the accountant asks you to analyze salary data of different employees in your company. … Read more

How to Print the Exception Without Exiting Your Python Program?

Problem Formulation Given a basic Python program. How to print an exception if it occurs without exiting the program? For example, consider the following program that raises a ZeroDivisionError: division by zero. The output is: You want the program to keep running and executing the print statement after giving you a note about the exception: … Read more

How to Get the Substring of a String in Python?

To get a substring of a given string in Python, you can use a popular feature called “slicing“. The syntax is string[start:stop:step] with the following meaning: start is the index of the first character included in the substring, stop is the index of the last character, but it is not itself included in the substring, … Read more