Articles on Trending Technologies

Technical articles with clear explanations and examples

Python Pandas - Determine if two CategoricalIndex objects contain the same elements

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 244 Views

To determine if two CategoricalIndex objects contain the same elements, use the equals() method. This method compares both the values and the categorical properties (categories and ordering) of the objects. What is CategoricalIndex? A CategoricalIndex is a pandas index type for categorical data with a fixed set of possible values (categories). It's memory-efficient for data with repeated values. Using equals() Method The equals()

Read More

Python Pandas CategoricalIndex - Map values using input correspondence like a dict

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 350 Views

To map values using input correspondence like a dictionary, use the CategoricalIndex.map() method in Pandas. This method allows you to transform categorical values by mapping them to new values using a dictionary-like object. Creating a CategoricalIndex First, let's create a CategoricalIndex with ordered categories − import pandas as pd # Create CategoricalIndex with ordered categories catIndex = pd.CategoricalIndex(["P", "Q", "R", "S", "P", "Q", "R", "S"], ...

Read More

Python Pandas - Set the categories of the CategoricalIndex to be unordered

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 315 Views

To set the categories of the CategoricalIndex to be unordered, use the as_unordered() method in Pandas. This method converts an ordered categorical index to an unordered one. Creating an Ordered CategoricalIndex First, let's create an ordered CategoricalIndex using the ordered=True parameter ? import pandas as pd # Create an ordered CategoricalIndex catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, ...

Read More

Python Pandas - Remove the specified categories from CategoricalIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 3K+ Views

To remove the specified categories from CategoricalIndex, use the remove_categories() method in Pandas. This method removes categories from the index and sets values that were in the removed categories to NaN. Creating a CategoricalIndex First, let's create a CategoricalIndex with some categories ? import pandas as pd # Create CategoricalIndex with categories p, q, r, s cat_index = pd.CategoricalIndex( ["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"] ) print("Original CategoricalIndex:") print(cat_index) print("Categories:") print(cat_index.categories) ...

Read More

Python Pandas CategoricalIndex - Add new categories

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 327 Views

To add new categories to a Pandas CategoricalIndex, use the add_categories() method. This method extends the available categories without changing the existing data values. Creating a CategoricalIndex First, let's create a CategoricalIndex with initial categories ? import pandas as pd # Create CategoricalIndex with ordered categories catIndex = pd.CategoricalIndex( ["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"] ) print("Original CategoricalIndex:") print(catIndex) Original CategoricalIndex: CategoricalIndex(['p', 'q', 'r', 's', 'p', 'q', 'r', 's'], categories=['p', ...

Read More

Python Pandas CategoricalIndex - Rename categories with dict-like new categories

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 252 Views

To rename categories with dict-like new categories, use the CategoricalIndex rename_categories() method in Pandas. This method allows you to map old category names to new ones using a dictionary. What is CategoricalIndex? CategoricalIndex can only take on a limited, and usually fixed, number of possible values. It's useful for representing data with a finite set of categories. Creating a CategoricalIndex First, let's create a CategoricalIndex with some sample data ? import pandas as pd # Create CategoricalIndex with ordered categories catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ...

Read More

Python Pandas CategoricalIndex - Get the categories of this categorical

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 592 Views

To get the categories of a categorical index, use the categories property of the CategoricalIndex in Pandas. A CategoricalIndex can only take on a limited, and usually fixed, number of possible values (categories). Creating a CategoricalIndex First, let's create a CategoricalIndex with specific categories and ordering ? import pandas as pd # Create CategoricalIndex with ordered categories catIndex = pd.CategoricalIndex( ["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"] ) print("Categorical Index...") print(catIndex) ...

Read More

Program to sort all elements in a given list and merge them into a string in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 405 Views

Suppose we are given a list of positive integers. We have to sort the list in descending order and then join all the elements to form a string. The goal is to arrange numbers so that the resulting concatenated string represents the largest possible number. So, if the input is like input = [415, 78, 954, 123, 5], then the output will be 954785415123. Approach To solve this, we need a custom comparison function that determines which of two numbers should come first when concatenated ? Define a function cmp() that takes two parameters l ...

Read More

Program to find a path a continuous path in a rectangular area without engaging a bomb in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 489 Views

Suppose we are given an array mat where the elements are of this form [p, q, r] where p and q are geometric coordinates and r is a radius value. The items in the array are the locations of bombs in a rectangular area of a given width w. The rectangle is infinitely long and is bounded by x coordinates x = 0 to x = w. The r value in the bombs position signifies the safety radius of a bomb, meaning anything less than that radius of the bomb will engage it. So, what we have to do is ...

Read More

Program to find out is a point is reachable from the current position through given points in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 539 Views

In a 2D space, we have a pointer at position (px, py) that needs to move to destination (qx, qy). The pointer can only move to adjacent cells: (x+1, y), (x-1, y), (x, y+1), or (x, y-1). We're given an array of paths containing intermediate points that must be processed serially. We need to find the minimum number of path points required to reach the destination, or return -1 if unreachable. Problem Example If we have px = 1, py = 1, qx = 2, qy = 3, paths = [[1, 2], [0, 1], [0, 2], [1, 3], ...

Read More
Showing 2891–2900 of 61,298 articles
« Prev 1 288 289 290 291 292 6130 Next »
Advertisements