Found 26504 Articles for Server Side Programming

Program to find number of unique people from list of contact mail ids in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:37:19

214 Views

Suppose we have a list of mail ids in a constants list. So for each row there may be more than one mail id of same person. The contact i is considered as duplicate when there's any j, where j < i such that contact j shares a common email with i. So we have to find the number of unique people in contacts.So, if the input is like contacts = [["alex@gmail.com", "alex@yahoo.com"], ["alex_25@yahoo.com", "alex@gmail.com"], ["bob15@gmail.com"] ], then the output will be 2, as the first and second contacts are sharing same mail ids, so they are same person, so ... Read More

Python Pandas - Get the maximum value from Ordered CategoricalIndex

AmitDiwan
Updated on 14-Oct-2021 11:12:51

418 Views

To get the maximum value from Ordered CategoricalIndex, use the catIndex.max() method in Pandas.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 max value −print("Maximum value from CategoricalIndex...", catIndex.max())ExampleFollowing is the code −import pandas as pd # CategoricalIndex can only take on a limited, and usually fixed, number of possible values. # Set the categories ... Read More

Program to check words can be found in matrix character board or not in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:31:36

562 Views

Suppose we have a matrix character board. Where each cell is holding a character. We also have a string called target, we have to check whether the target can be found in the matrix by going left-to-right, or up-to-down unidirectional way, or not.So, if the input is likeantsspinlapsWord = “tip”then the output will be True, you can see the third column (top to bottom) is forming "tip".To solve this, we will follow these steps −for each i in board, doi := make word from characters present in iif word is present in i, thenreturn Truei := 0while i < row ... Read More

Python Pandas - Get the minimum value from Ordered CategoricalIndex

AmitDiwan
Updated on 14-Oct-2021 11:10:28

145 Views

To get the minimum value from Ordered CategoricalIndex, use the catIndex.min() method in Pandas. 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 min value −print("Minimum value from CategoricalIndex...", catIndex.min())ExampleFollowing is the code −import pandas as pd # CategoricalIndex is the Index based on an underlying Categorical # Set the categories for the categorical using ... Read More

Python Pandas - Create an Index based on an underlying Categorical

AmitDiwan
Updated on 14-Oct-2021 11:08:53

528 Views

To create an Index based on an underlying Categorical, use the pandas.CategoricalIndex() method.At first, import the required libraries −import pandas as pdCategoricalIndex is the Index based on an underlying Categorical. CategoricalIndex 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"] )Display the Categorical Index −print("Categorical Index...", catIndex)Get the categories −print("DisplayingCategories from CategoricalIndex...", catIndex.categories)ExampleFollowing is the code −import pandas as pd ... Read More

Program to find maximum profit we can make by holding and selling profit in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:09:04

669 Views

Suppose we have a list of numbers called nums, that is representing stock prices of a company in chronological order. We can buy at most one share of stock per day, but you can hold onto multiple stocks and can sell stocks on any number of days. Return the maximum profit you can earn.So, if the input is like nums = [3, 4, 7, 3, 5], then the output will be 9, because we can buy the stocks at 3 and 4 and sell them at 7. Then again buy at 3 and sell at 5. Total profit (7 - ... Read More

Python Pandas - Create RangeIndex from a range object

AmitDiwan
Updated on 14-Oct-2021 11:07:03

903 Views

To create RangeIndex from a range object, use the pd.RangeIndex.from_range(range()) method in Pandas.At first, import the required libraries −import pandas as pdCreate RangeIndex −index = pd.RangeIndex.from_range(range(10, 30)) Display the RangeIndex −print("RangeIndex...",index)ExampleFollowing is the code −import pandas as pd # RangeIndex index = pd.RangeIndex.from_range(range(10, 30)) # Display the RangeIndex print("RangeIndex...",index) # Display the start value print("RangeIndex start value...",index.start) # Display the end value print("RangeIndex end value...",index.stop)OutputThis will produce the following output −RangeIndex... RangeIndex(start=10, stop=30, step=1) RangeIndex start value... 10 RangeIndex end value... 30

Python Pandas - Display the value of the step parameter of RangeIndex

AmitDiwan
Updated on 14-Oct-2021 11:05:37

298 Views

To display the value of the step parameter of RangeIndex, use the index.step property in Pandas.At first, import the required libraries −import pandas as pdRangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges. Create a range index with start, stop and step. The name is the name to be stored in the index.index = pd.RangeIndex(start=10, stop=30, step=2, name="data") Display the step parameter value −print("RangeIndex step value...", index.step)ExampleFollowing is the code −import pandas as pd # RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges. # Create a range index with start, ... Read More

Program to find minimum time required to complete tasks with k time gap between same type tasks in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:06:07

386 Views

Suppose we have a list of integers called tasks where each item represents a different task type, we also have a non-negative integer say k. Each task takes one unit of time to complete and the tasks must be completed in correct order, but we must have k units of time between doing two same type tasks. At any time, either we can do a task or wait. We have to find the amount of time it takes to complete all the tasks.So, if the input is like tasks = [0, 1, 1, 2] k = 2, then the output ... Read More

Python Pandas - Display the value of the stop parameter of RangeIndex

AmitDiwan
Updated on 14-Oct-2021 11:04:10

439 Views

To display the value of the stop parameter of RangeIndex, use the index.stop property in Pandas.At first, import the required libraries −import pandas as pdRangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges. Create a range index with start, stop and step. The name is the name to be stored in the index.index = pd.RangeIndex(start=5, stop=20, step=2, name="data") Display the RangeIndex −print("RangeIndex...", index)Display the stop parameter value −print("RangeIndex stop value...", index.stop) ExampleFollowing is the code −import pandas as pd # RangeIndex is a memory-saving special case of Int64Index limited to representing monotonic ranges. # Using ... Read More

Advertisements