Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 833 of 2650
301 Views
To rename categories, use the CategoricalIndex rename_categories() method in Pandas. At first, import the required libraries −import pandas as pdCategoricalIndex can only take on a limited, and usually fixed, number of possible values. Set the categories for the categorical using the "categories" parameter. Treat the categorical as ordered using the "ordered" parameter −catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])Rename categories. Set the new categories that will replace the old categories −print("CategoricalIndex after renaming categories...", catIndex.rename_categories([5, 10, 15, 20])) ExampleFollowing is the code −import pandas as pd # CategoricalIndex can only take ... Read More
115 Views
To check whether the categories have an ordered relationship, use the ordered property of the CategoricalIndex.At first, import the required libraries −import pandas as pdSet the categories for the categorical using the "categories" parameter. Treat the categorical as ordered using the "ordered" parameter −catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])Display the Categorical Index −print("Categorical Index...", catIndex) Get the categories −print("DisplayingCategories from CategoricalIndex...", catIndex.categories)Check categories for ordered relationship −print("Does categories have ordered relationship...", catIndex.ordered) ExampleFollowing is the code −import pandas as pd # CategoricalIndex can only take on a limited, and usually ... Read More
466 Views
To get the categories of this categorical, use the categories property of the CategoricalIndex in Pandas. At first, import the required libraries −import pandas as pdCategoricalIndex can only take on a limited, and usually fixed, number of possible values (categories. Set the categories for the categorical using the "categories" parameter. Treat the categorical as ordered using the "ordered" parameter −catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])Display the Categorical Index −print("Categorical Index...", catIndex) Get the categories −print("Displaying Categories from CategoricalIndex...", catIndex.categories)ExampleFollowing is the code −import pandas as pd # CategoricalIndex can only ... Read More
363 Views
To get the category codes of this categorical, use the codes property of the CategoricalIndex in Pandas. At first, import the required libraries −import pandas as pdCategoricalIndex can only take on a limited, and usually fixed, number of possible values (categories). Set the categories for the categorical using the "categories" parameter. Treat the categorical as ordered using the "ordered" parameter. Codes are an array of integers which are the positions of the actual values in the categories array −catIndex = pd.CategoricalIndex(["p", "q", "r", "s", "p", "q", "r", "s"], ordered=True, categories=["p", "q", "r", "s"])Display the Categorical Index −print("Categorical Index...", catIndex) Get ... Read More
287 Views
Suppose we are given a matrix that contains integer values. We have to find out the submatrices from the matrix where the sum of elements of the matrices is equal to a given target sum value. We return the number of submatrices.So, if the input is like0010010001011101and target = 5, then the output will be 3.The number of submatrices whose sum of elements is equal to 6 is 2.To solve this, we will follow these steps −n := size of matm := (if n is same as 0, then 0, otherwise size of mat[0])if m > n, then −Define one ... Read More
476 Views
Suppose we are given a matrix that contains only two values; 1s and 0s. We have to find out the number of submatrices in the given matrix that contains all 1s. We print the value as output.So, if the input is like0010010001011101then the output will be 12.To solve this, we will follow these steps −n := size of matrixm := size of matrix[0]Define an array add of size: n+1 x m+1.for initialize i := 0, when i < n, update (increase i by 1), do −for initialize j := 0, when j < m, update (increase j by 1), do ... Read More
271 Views
Suppose we have a list of 2D Cartesian coordinate points (x, y). We can connect (x0, y0) and (x1, y1), whose cost is |x0 - x1| + |y0 - y1|. If we are allowed to connect any number of points, we have to find the minimum cost necessary such that every point is connected by a path.So, if the input is like points = [[0, 0], [0, 2], [0, -2], [2, 0], [-2, 0], [2, 3], [2, -3]], then the output will be 14 because, from (0, 0) to (0, 2), (0, -2), (2, 0), (-2, 0), costs are 2, ... Read More
259 Views
Suppose we are given a list of positive integers. We have to sort the list in descending order and then have to join all the elements in it to form a string. We return the joined string.So, if the input is like input = [415, 78, 954, 123, 5], then the output will be 954785415123To solve this, we will follow these steps −Define a function cmp() . This will take l, rif integer value of (string representation of (l) + string representation of (r)) > integer value of (string representation of (r) + string representation of (l)), thenreturn 1otherwise, return ... Read More
336 Views
Suppose we are given an array mat where the elements are of this form [p, q, r] where p, 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 to ... Read More
Program to find out is a point is reachable from the current position through given points in Python
364 Views
Suppose in a 2D space a pointer is located at a point p that has coordinates (px, py). Now the pointer has to move to another point q having coordinates (qx, qy). The pointer just cannot move freely, it can travel to q if there are some points located in between. We are given an array of points "paths" that contain various coordinate points. The pointer can move to a point if it is located at (x+1, y) or (x, y+1) or (x-1, y) or (x, y-1) from the current position of the pointer. The given points in the array ... Read More