How to Convert List of Lists to a Pandas Dataframe

Problem: You’re given a list of lists. Your goal is to convert it into a Pandas Dataframe. Example: Say, you want to compare salary data of different companies and job descriptions. You’ve obtained the following salary data set as a list of list: How can you convert this into a Pandas Dataframe? DataFrame() Solution: The … Read more

How to Convert List of Lists to NumPy Array?

Short answer: Convert a list of lists—let’s call it l—to a NumPy array by using the standard np.array(l) function. This works even if the inner lists have a different number of elements. Convert List of Lists to 2D Array Problem: Given a list of lists in Python. How to convert it to a 2D NumPy … Read more

Python List of Lists – A Helpful Illustrated Guide to Nested Lists in Python

There’s an element of confusion regarding the term “lists of lists” in Python. I wrote this most comprehensive tutorial on list of lists in the world to remove all those confusions by beginners in the Python programming language. This multi-modal tutorial consists of: Source code to copy&paste in your own projects. Interactive code you can … Read more

Python List to Tuple

Problem: Given a Python list with n elements. How to convert it into a tuple with the same n elements? Examples: Note Tuple: Tuples are similar to lists—with the difference that you cannot change the tuple values (tuples are immutable) and you use parentheses rather than square brackets. Solution: Use the built-in Python tuple() function … Read more

Python sum() List – A Simple Illustrated Guide

Summing up a list of numbers appears everywhere in coding. Fortunately, Python provides the built-in sum() function to sum over all elements in a Python list—or any other iterable for that matter. (Official Docs) The syntax is sum(iterable, start=0): Argument Description iterable Sum over all elements in the iterable. This can be a list, a … Read more

Print a Python List Beautifully [Click & Run Code]

How to print a Python list in a beautiful and fully customizable way? This article shows you six effective ways of doing it. By studying these alternatives, you’ll not only learn how to print lists in Python, you’ll become a better coder overall. If you just want to know the best way to print a … Read more

The Dot Character in a Character Set – What Does It Match?

Given is the following regular expression: Note the dot character inside the character set. As you may know, the dot metacharacter matches an arbitrary character if it is used outside a character set. But what does it match if you place the dot character inside a regex character set? The answer is that the dot … Read more

Matplotlib 3D Plot [Tutorial]

Photo by Aida L on Unsplash

Are you tired with the same old 2D plots? Do you want to take your plots to the next level? Well look no further, it’s time to learn how to make 3D plots in matplotlib. In addition to import matplotlib.pyplot as plt and calling plt.show(), to create a 3D plot in matplotlib, you need to: … Read more

How to Get the Number of Elements in a Python List?

To get the number of elements in a Python list, use the len(list) function. You don’t need to import any external library because len() is a Python built-in function. You can use it to get the number of elements of several built-in and library types in Python such as tuples and sets. Here’s the minimal … Read more

Matplotlib 3D Plot Advanced

Photo by Ricardo Gomez Angel on Unsplash

If you’ve already learned how to make basic 3d plots in maptlotlib and want to take them to the next level, then look no further. In this article, I’ll teach you how to create the two most common 3D plots (surface and wireframe plots) and a step-by-step method you can use to create any shape … Read more