How to Create a DataFrame in Pandas?

In Python’s pandas module, DataFrames are two-dimensional data objects. You can think of them as tables with rows and columns that contain data. This article provides an overview of the most common ways to instantiate DataFrames. We follow the convention to rename the pandas import to pd. Create a DataFrame From a CSV File Creating … Read more

The Ultimate Guide To Python Tuples

Python has several built-in data structures such as Lists, Sets and Dictionaries (check out the articles!).In this article, you’ll learn everything you need to know about tuples including real world examples. Tuple Motivating Example Did you ever have a function from which you wanted to return several values? Say, you’ve got a function translate(text, target_language) … Read more

Python Freelancing: My First Fiverr Gig and How I Solved It

Basic Webscraping Script in Python | Requests | BeautifulSoup | ArgParse Sold Gig ($35) This is the gig description I offered on my profile to get my first gig: An email marketing company hired me to write a Python script that satisfies the following requirements. Requirements What is the input? (file, file type, email, text,…) … Read more

How to Sort a List of Tuples? – Most Pythonic Way!

Did you already try to sort a list of tuples? And when you saw the result, it wasn’t quite what you expected? Well, this happened to me when I went deeper into Python, and I suppose it also happened to you since you are looking for a solution. To me, this shows that you are … Read more

How to Get Specific Elements From a List? – Most Pythonic Way!

Quick Article Summary to get a specific element from a list: Get elements by index use the operator [] with the element’s index use the list’s method pop(index) use slicing lst[start:stop:step] to get several elements at once use the function itemgetter() from the operator module Get elements by condition use the filter() function use a … Read more

The Most Pythonic Way to Remove Multiple Items From a List

Python’s built-in list data structure has many powerful methods any advanced Python programmer must be familiar with. However, some operations on lists can’t be performed simply by calling the right method. You can add a single item to a list using the method append(item) on the list. If you want to add a list of … Read more

Python 3.8 Walrus Operator (Assignment Expression)

The release of Python 3.8 came with an exciting new feature: the Walrus Operator. It’s an assignment expression, or in simpler terms an assignment inside an expression. Let’s dive into practice immediately and look at the following code: We have a list of users whose data is represented in a dictionary. We want to count … Read more

List to Dict — Convert a List Into a Dictionary in Python

That’s a very common question and the answer is: It depends.It depends on the data in the list and how you want it to be represented in the dictionary. In this article we go over six different ways of converting a list to a dictionary. You can also watch my advanced one-liner video where we … Read more