Python dict.copy() Method

πŸ“– Summary: There are many different ways to copy the dictionary data structure objects in Python. In this tutorial, I will show you the built-in dict.copy() method, which is a very useful method for copying dictionaries. Description Whenever the dict.copy() method is applied to a dictionary, a new dictionary is made, which contains a copy … Read more

Python Excel – Manipulating Worksheet Data

Building on the skill(s) you learned earlier, Part 3 centers around manipulating the data. This skill is another must-have if you are interested in pursuing a career as a Data Scientist. Background After completing Part 2 of this series, you should be comfortable using Python to: access a single row/column value, access a range of … Read more

Python Dictionary clear()

In this blog post, you’ll learn about the Python Dictionary clear() method. But, before I cover the clear() method I would like to give a brief definition of what a Python Dictionary is. Definition: A Python dictionary data structure is a collection of key-value pairs that are unordered, and are accessed by a key instead … Read more

Pandas loc() and iloc() – A Simple Guide with Video

In this tutorial, we are covering the Pandas functions loc() and iloc() which are used for data selection operations on dataframes. By using the loc() function, we access a group of rows and/or columns based on their respective labels, whereas the iloc() function is an integer-location-based way to access these groups. Getting values with the … Read more

Python Dictionary: How to Create, Add, Replace, Retrieve, Remove

Python defines the dictionary data type as an unordered collection that contains key:value pairs. The key:value pairs (separated by commas) are wrapped inside curly braces ({}). Β  Each key inside the dictionary must be unique and immutable. Dictionary keys can be one of the following data types: integer, string, or tuple. Dictionary keys can not … Read more

Python Namespaces Made Simple

Namespace are everywhere in Python whether you realize it or not. If you don’t know about Python namespaces, you’ll eventually introduce nasty bugs into your Python code. Let’s fix this once and for all! πŸ™‚ As you read over the article, you can watch my explainer video: Why Namespaces? In many classes with 30+ students, … Read more

The Quickselect Algorithm – A Simple Guide with Video

What is the Quickselect algorithm? The Quickselect algorithm is a computer algorithm designed to find the kth (e.g. smallest or largest) element from an unordered list. It is based on the idea behind the Quicksort algorithm, invented by the same author, Sir Charles Anthony Richard (Tony) Hoare. Here, k stands for the index of an … Read more

How to Convert a String to a Dictionary in Python?

Problem Formulation Given a string representation of a dictionary. How to convert it to a dictionary? Input: ‘{“1”: “hi”, “2”: “alice”, “3”: “python”}’ Output: {‘a’: 1, ‘b’: 2, ‘c’: 3} Method 1: eval() The built-in eval() function takes a string argument, parses it as if it was a code expression, and evaluates the expression. If … Read more