How to Filter Data from an Excel File in Python with Pandas

Problem Formulation and Solution Overview This article will show different ways to read and filter an Excel file in Python. To make it more interesting, we have the following scenario: Sven is a Senior Coder at K-Paddles. K-Paddles manufactures Kayak Paddles made of Kevlar for the White Water Rafting Community. Sven has been asked to … Read more

Python | Split String Every “N” Characters

Summary: One of the easiest ways to split a string after every n character is to use a list comprehension to and slice the string accordingly to extract every n character of the given string and store them in a list. The items of this list represent the required split substrings.A quick Look at the … Read more

Python Convert Hex String to Binary

πŸ’¬ Question: How to convert a given hex string such as ‘0xF’ to a binary number such as ‘0b1111′? There are multiple variants of this problem depending on how you want the conversion and from which type to which type. In this article, we’ll go over the different methods from simple to more sophisticated. Let’s … Read more

Hex String to Hex Integer in Python

πŸ’¬ Question: Given a hexadecimal string such as ‘0xf’ in Python. How to convert it to a hexadecimal number in Python so that you can perform arithmetic operations such as addition and subtraction? The hexadecimal string representation with the ‘0x’ prefix indicates that the digits of the numbers do have a hexadecimal base 16. In … Read more

PyTrends – Google Trends API for Python

Keeping Up With Market Changes By Using Google Trends API In this fast-moving world, people’s needs are constantly changing. To know about shifting behaviors, you can use Google Trends.Β Β  This free tool provides data through search requests across Google Search, YouTube, Shopping, and Images. By entering a keyword or a topic, you can explore what … Read more

How to Convert Hex String to Bytes in Python?

Problem Formulation Given a string in hexadecimal form: How to convert the hex string to a bytes object in Python? Here are a few examples: Hex String Bytes Object ’01’ b’\x01′ ’04’ b’\x04′ ’08’ b’\x08′ ’01 0a’ b’\x01\n’ ’01 02 0e 0f 0f’ b’\x01\x02\x0e\x0f\x0f’ ‘0f 0f’ b’\x0f\x0f’ Hex String to Bytes using bytes.fromhex(hex_string) To convert … Read more

Python | Split String at Position

Summary: You can split a given string at a specific position/index using Python’s string–slicing syntax. Minimal Example: Problem Formulation πŸ’¬Problem: Given a string, how will you split the given string at any given position? Let’s have a look at a couple of examples that demonstrate what the problem asks you to do: β—ˆExample 1 The following … Read more

Python Regex Named Groups

Before we dive into named groups, let’s quickly recap normal capture groups in Python. If you already know normal “unnamed capturing groups” well, feel free to skip the first section and move right away to the next one about named capture groups in Python. πŸ‘‡ What Are Python Regex Groups? A normal Python regex group … Read more

6 Ways to Remove Python List Elements

Problem Formulation and Solution Overview This article will show you how 6 ways to remove List elements in Python. To make it more interesting, we have the following running scenario: Suppose you have a Christmas List containing everyone to buy a gift for. Once a gift is purchased, remove this person from the List. Once … Read more

Python Return Error From Function

Problem Formulation πŸ’¬ Question: How do you write a function that returns a real Python error instead of an “error code” such as -1 or None in case something got wrong? For example, you may want to check the function input arguments for having the correct type or length (in the case of iterable arguments) … Read more