Python: How to Remove a Key from a Dictionary

Introduction In this article, we’ll take a look at how to remove keys from Python dictionaries. This can be done with the pop() function, the del keyword, and with dict comprehensions. Remove a Key Using pop(key,d) The pop(key, d) function removes a key from a dictionary and returns its value. It takes two arguments, the key is removed and the optional value to return if the key isn’t found. Here’s an example of popping an element with only the required […]

Read more

Covariance and Correlation in Python

Introduction Working with variables in data analysis always drives the question: How are the variables dependent, linked, and varying against each other? Covariance and Correlation measures aid in establishing this. Covariance brings about the variation across variables. We use covariance to measure how much two variables change with each other. Correlation reveals the relation between the variables. We use correlation to determine how strongly linked two variables are to each other. In this article, we’ll learn how to calculate the […]

Read more

How to Rename Pandas DataFrame Column in Python

Introduction Pandas is a Python library for data analysis and manipulation. Almost all operations in pandas revolve around DataFrames. A Dataframe is is an abstract representation of a two-dimensional table which can contain all sorts of data. They also enable us give all the columns names, which is why oftentimes columns are referred to as attributes or fields when using DataFrames. In this article we’ll see how we can rename an already existing DataFrame‘s columns. There are two options for […]

Read more

Python: Get Size of Dictionary

Introduction In this article, we’ll take a look at how to find the size of a dictionary in Python. Dictionary size can mean its length, or space it occupies in memory. To find the number of elements stored in a dictionary we can use the len() function. To find the size of a dictionary in bytes we can use the getsizeof() function of the sys module. To count the elements of a nested dictionary, we can use a recursive function. […]

Read more

Python: How to Handle Missing Data in Pandas DataFrame

Introduction Pandas is a Python library for data analysis and manipulation. Almost all operations in pandas revolve around DataFrames, an abstract data structure tailor-made for handling a metric ton of data. In the aforementioned metric ton of data, some of it is bound to be missing for various reasons. Resulting in a missing (null/None/Nan) value in our DataFrame. Which is why, in this article, we’ll be discussing how to handle missing data in a Pandas DataFrame. Data Inspection Real-world datasets […]

Read more

How to Format Number as Currency String in Python

Introduction Having to manually format a number as a currency string can be a tedious process. You may have just a few lines of modifications to make, however, when we need to do a fair bit of conversions, it becomes very tedious. The first step to automating these kind of tasks will require a function. In this article, we’ll be going over a few methods you can use to format numbers as currency strings in Python. Methods for Formatting Numbers […]

Read more

Seaborn Box Plot – Tutorial and Examples

Introduction Seaborn is one of the most widely used data visualization libraries in Python, as an extension to Matplotlib. It offers a simple, intuitive, yet highly customizable API for data visualization. In this tutorial, we’ll take a look at how to plot a Box Plot in Seaborn. Box plots are used to visualize summary statistics of a dataset, displaying attributes of the distribution like the data’s range and distribution. Import Data We’ll need to select a dataset with continuous features […]

Read more

Integrating MongoDB with Flask Using Flask-PyMongo

Introduction Building a web app almost always means dealing with data from a database. There are various databases to choose from, depending on your preference. In this article, we shall be taking a look at how to integrate one of the most popular NoSQL databases – MongoDB – with the Flask micro-framework. They are several Flask extensions for integrating MongoDB, here we’ll be using the Flask-PyMongo extension. We will also be working on a simple Todo-List API to explore the […]

Read more

Matplotlib Box Plot – Tutorial and Examples

Introduction There are many data visualization libraries in Python, yet Matplotlib is the most popular library out of all of them. Matplotlib’s popularity is due to its reliability and utility – it’s able to create both simple and complex plots with little code. You can also customize the plots in a variety of ways. In this tutorial, we’ll cover how to plot Box Plots in Matplotlib. Box plots are used to visualize summary statistics of a dataset, displaying attributes of […]

Read more

How to Iterate Over a Dictionary in Python

Introduction Dictionaries are one of the most used data structures in all of software development, and for a good reason. They allow us to store our data in neat key, value pairs, which in turn gives us the ability to, on average, access our data in O(1) time. While using a dictionary it’s important to know how to iterate over it. Not being able to recover the data you stored makes it practically useless. In this article, we’ll see how […]

Read more
1 5 6 7 8 9 54