Server Side Programming Articles - Page 1964 of 2650

Boolean Indexing in Pandas

Hafeezul Kareem
Updated on 02-Jan-2020 06:58:52

2K+ Views

Boolean indexing helps us to select the data from the DataFrames using a boolean vector. We need a DataFrame with a boolean index to use the boolean indexing. Let's see how to achieve the boolean indexing.Create a dictionary of data.Convert it into a DataFrame object with a boolean index as a vector.Now, access the data using boolean indexing.See the example below to get an idea.Exampleimport pandas as pd # data data = {    'Name': ['Hafeez', 'Srikanth', 'Rakesh'],    'Age': [19, 20, 19] } # creating a DataFrame with boolean index vector data_frame = pd.DataFrame(data, index = [True, False, True]) ... Read More

Calendar Functions in Python - ( calendar(), month(), isleap()?)

Hafeezul Kareem
Updated on 02-Jan-2020 06:53:15

612 Views

We can perform the calendar operations using the calendar module in Python. Here, we are going to learn about the different methods of calendar class instance.calendar.calendar(year)The calendar class instance returns the calendar of the year. Let's see one example.Example Live Demo# importing the calendar module import calendar # initializing year year = 2019 # printing the calendar print(calendar.calendar(year))OutputIf you run the above code, you will get the following results.calendar.firstweekday()The method calendar.firstweekday() returns the first weekday in the week i.e.., MONDAY.Example Live Demo# importing the calendar import calendar # getting firstweekday of the year print(calendar.firstweekday())OutputIf you run the above program, you will get ... Read More

Calendar Functions in Python -(monthrange(), prcal(), weekday()?)

Hafeezul Kareem
Updated on 02-Jan-2020 06:47:01

607 Views

We are going to explore different methods of calendar module in this tutorial. Let's see one by one.calendar.monthrange(year, month)The method calendar.monthrange(year, month) returns starting weekday number and number of days of the given month. It returns two values in a tuple. Let's see one example.Example Live Demo# importing the calendar module import calendar # initializing year and month year = 2019 month = 1 # getting the tuple of weekday and no. of days weekday, no_of_days = calendar.monthrange(year, month) print(f'Weekday number: {weekday}') print(f'No. of days: {no_of_days}')OutputIf you run the above code, you will get the following results.Weekday number: 1 No. of ... Read More

casefold() string in Python Program

Hafeezul Kareem
Updated on 02-Jan-2020 06:31:14

178 Views

In this tutorial, we are going to discuss the string method str.casefold(). It doesn't take any arguments. The return value of the method is a string that is suitable for the caseless comparisons.What are caseless comparisons? For example, the german lower case letter ß is equivalent to ss. The str.casefold() method returns the ß as ss. It converts all the letters to lower case.Example Live Demo# initialising the string string = "TUTORIALSPOINT" # printing the casefold() version of the string print(string.casefold())OutputIf run the above program, you will get the following result.tutorialspointLet's see the example where caseless comparison works. If you directly compare ... Read More

Matrix Multiplication and Normalization in C program

Arnab Chakraborty
Updated on 02-Jan-2020 06:18:27

860 Views

Matrix MultiplicationNow procedure of Matrix Multiplication is discussed. The Matrix Multiplication can only be performed, if it satisfies certain condition. Suppose two matrices are P and Q, and their dimensions are P (a x b) and Q (z x y) the resultant matrix can be found if and only if b = x. Then the order of the resultant matrix R will be (m x q).AlgorithmmatrixMultiply(P, Q): Assume dimension of P is (a x b), dimension of Q is (z x y) Begin    if b is not same as z, then exit    otherwise define R matrix as (a ... Read More

Convert a BST to a Binary Tree such that sum of all greater keys is added to every key in C++

Ayush Gupta
Updated on 02-Jan-2020 06:01:04

126 Views

In this tutorial, we will be discussing a program to convert a BST to a binary tree such that the sum of all greater keys is added to every key.For this, we will be provided with a Binary Search tree. Our task is to convert that tree into a binary tree with the sum of all greater keys added to the current key. This will be done by the reverse in order of the given BST along with having the sum of all the previous elements and finally adding it to the current element.Example Live Demo#include using namespace std; //node ... Read More

Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue) in C++

Ayush Gupta
Updated on 02-Jan-2020 05:54:48

466 Views

In this tutorial, we will be discussing a program to convert a binary tree to a threaded binary tree using a queue data structure.For this, we will be provided with a binary tree. Our task is to convert that particular binary tree into a threaded binary tree by adding additional routes for quicker inorder traversal with the help of a queue data structure.Example Live Demo#include #include using namespace std; //node structure for threaded tree struct Node {    int key;    Node *left, *right;    bool isThreaded; }; //putting the inorder pattern into a queue void convert_queue(Node* root, std::queue* ... Read More

Convert a Binary Tree to a Circular Doubly Link List in C++

Ayush Gupta
Updated on 02-Jan-2020 05:50:16

156 Views

In this tutorial, we will be discussing a program to convert a binary tree to a circular doubly linked list.For this, we will be provided with a binary tree. Our task will be to convert the left and right nodes to the left and right elements respectively. And take the inorder of the binary tree to be the sequence order of the circular linked listExample Live Demo#include using namespace std; //node structure of the binary tree struct Node{    struct Node *left, *right;    int data; }; //appending rightlist to the end of leftlist Node *concatenate(Node *leftList, Node *rightList){    //if ... Read More

Convert a Binary Tree such that every node stores the sum of all nodes in its right subtree in C++

Ayush Gupta
Updated on 02-Jan-2020 05:47:41

162 Views

In this tutorial, we will be discussing a program to convert a binary tree such that every node stores the sum of all nodes in its right subtree.For this, we will be provided with a binary tree. Our task is to return another tree where every node must be equal to the sum of the node and its right subtree.Example Live Demo#include using namespace std; //node structure of tree struct Node {    int data;    Node *left, *right; }; //creation of a new node struct Node* createNode(int item){    Node* temp = new Node;    temp->data = item;   ... Read More

Convert a Binary Tree into its Mirror Tree in C++

Ayush Gupta
Updated on 02-Jan-2020 05:44:58

187 Views

In this tutorial, we will be discussing a program to convert a binary tree into its mirror tree.For this, we will be provided with a binary tree. Our task will be to swap the values on the left and the right end creating a mirror tree from the given binary tree.Example Live Demo#include using namespace std; //binary tree node structure struct Node{    int data;    struct Node* left;    struct Node* right; }; //creation of a new node with no child nodes struct Node* newNode(int data){    struct Node* node = (struct Node*)malloc(sizeof(struct Node));    node->data = data;    node->left ... Read More

Advertisements