How to Get the Substring of a String in Python?

To get a substring of a given string in Python, you can use a popular feature called “slicing“. The syntax is string[start:stop:step] with the following meaning: start is the index of the first character included in the substring, stop is the index of the last character, but it is not itself included in the substring, … Read more

How to Select Multiple Columns in Pandas

The easiest way to select multiple columns in Pandas is to pass a list into the standard square-bracket indexing scheme. For example, the expression df[[‘Col_1’, ‘Col_4, ‘Col_7’]] would access columns ‘Col_1’, ‘Col_4’, and ‘Col_7’. This is the most flexible and concise way for only a couple of columns. To learn about the best 3 ways … Read more

Python – Inverse of Normal Cumulative Distribution Function (CDF)

Problem Formulation How to calculate the inverse of the normal cumulative distribution function (CDF) in Python? Method 1: scipy.stats.norm.ppf() In Excel, NORMSINV is the inverse of the CDF of the standard normal distribution. In Python’s SciPy library, the ppf() method of the scipy.stats.norm object is the percent point function, which is another name for the … Read more

Reverse a String in Python

There are four main ways to reverse a string in Python: Slicing s[::-1] with negative step size traverses the string from right to left. ”.join(reversed(s)) first creates an iterable of characters in reversed order, and then joins these characters to obtain the reversed string. A for loop using the range(len(s)-1, -1, -1) function traverses the … Read more

How to Print Subscript in Python?

Problem Formulation Given two strings x and y. Create a new string xy and print it to the shell. Consider the following examples: INPUT x = ‘hi’ y = ‘finxter’ OUTPUT: hifinxter INPUT x = ‘2’ y = ‘4’ OUTPUT: 24 INPUT x = ‘abc’ y = ‘[1, 2, 3]’ OUTPUT: abc[1, 2, 3] Solution … Read more

List of Unicode Superscript Characters

Character Description Character U+2070 SUPERSCRIPT ZERO ⁰ U+2071 SUPERSCRIPT LATIN SMALL LETTER I ⁱ U+2074 SUPERSCRIPT FOUR ⁴ U+2075 SUPERSCRIPT FIVE ⁡ U+2076 SUPERSCRIPT SIX ⁢ U+2077 SUPERSCRIPT SEVEN ⁷ U+2078 SUPERSCRIPT EIGHT ⁸ U+2079 SUPERSCRIPT NINE ⁹ U+207A SUPERSCRIPT PLUS SIGN ⁺ U+207B SUPERSCRIPT MINUS ⁻ U+207C SUPERSCRIPT EQUALS SIGN ⁼ U+207D SUPERSCRIPT LEFT … Read more

How to Print Superscript in Python?

Problem Formulation Given two strings x and y. Create a new string xy and print it to the shell. Consider the following examples: INPUT x = ‘hi’ y = ‘finxter’ OUTPUT: hifinxter INPUT x = ‘2’ y = ‘4’ OUTPUT: 24 INPUT x = ‘abc’ y = ‘[1, 2, 3]’ OUTPUT: abc[1, 2, 3] Solution … Read more

Python Bitwise Operators [Full Guide + Videos]

Bitwise operators perform operations on the binary (bit) representation of integers. Background: Each integer is first written as a binary number that is a sequence of digits 0 or 1. For example: 0 is written as “0” 1 is written as “1” 2 is written as “10” 3 is written as “11” 4 is written … Read more

NumPy Broadcasting – A Simple Tutorial

Broadcasting describes how NumPy automatically brings two arrays with different shapes to a compatible shape during arithmetic operations. Generally, the smaller array is “repeated” multiple times until both arrays have the same shape. Broadcasting is memory-efficient as it doesn’t actually copy the smaller array multiple times. Here’s a minimal example: Let’s have a more gentle … Read more