Found 26504 Articles for Server Side Programming

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

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

202 Views

To display the value of the start parameter of RangeIndex, use the index.start 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. Using RangeIndex may in some instances improve computing speed. 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 start parameter value −print("RangeIndex start value...", index.start) ExampleFollowing is the code −import pandas as pd # Create a range index with ... Read More

Program to find array by swapping consecutive index pairs in Python

Arnab Chakraborty
Updated on 14-Oct-2021 11:03:24

483 Views

Suppose we have a list of numbers called nums, we have to return the list by swapping each consecutive even indexes with each other, and swapping each consecutive odd indexes with each other.So, if the input is like nums = [8, 5, 3, 4, 8, 9, 3, 6, 4, 7], then the output will be [3, 4, 8, 5, 3, 6, 8, 9, 4, 7]To solve this, we will follow these steps −for i in range 0 to size of nums - 2, increase by 4, doif i + 2 < size of nums, thenswap nums[i] and nums[i + 2]if ... Read More

Python Pandas - How to create a RangeIndex

AmitDiwan
Updated on 14-Oct-2021 11:02:01

1K+ Views

To create a RangeIndex, use the pandas.RangeIndex() method 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. Using RangeIndex may in some instances improve computing speed.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 start parameter value −print("RangeIndex start value...", index.start)Display the stop parameter value −print("RangeIndex stop value...", index.stop) Display the step parameter value −print("RangeIndex step value...", index.step)ExampleFollowing is the code −import pandas as pd ... Read More

Python Pandas - Compute slice locations for input labels

AmitDiwan
Updated on 14-Oct-2021 10:58:40

113 Views

To compute slice locations for input labels, use the index.slice_locs() method. At first, import the required libraries −import pandas as pdCreate Pandas index object −index = pd.Index(list('pqrstuvwxyz')) Display the Pandas index −print("Pandas Index...", index)Get the slice locations. The "start" is the label to begin with. The "end" is the label to end withprint("The slice locations with start and stop...", index.slice_locs(start='q', end='v')) ExampleFollowing is the code −import pandas as pd # Create Pandas index object index = pd.Index(list('pqrstuvwxyz')) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements ... Read More

Python Pandas - Compute the slice indexer for input labels

AmitDiwan
Updated on 14-Oct-2021 10:57:14

204 Views

To compute the slice indexer for input labels, use the index.slice_indexer() method. At first, import the required libraries −import pandas as pdCreate Pandas index object −index = pd.Index(list('pqrstuvwxyz')) Display the Pandas index −print("Pandas Index...", index)Get the slice indexer. The "start" is the label to begin with. The "end" is the label to end with −print("The slice indexer with start and stop...", index.slice_indexer(start='s', end='w')) ExampleFollowing is the code −import pandas as pd # create Pandas index object index = pd.Index(list('pqrstuvwxyz')) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number ... Read More

Program to check two strings can be equal by swapping characters or not in Python

Arnab Chakraborty
Updated on 14-Oct-2021 10:35:29

719 Views

Suppose we have two lowercase strings s and t, they are of the same length. We can select one character from s and another from t and swap them. We can do this operation any number of times we want. Finally, we have to check whether it's possible to make the two strings same or not.So, if the input is like s = "abcd" t = "cdab", then the output will be TrueTo solve this, we will follow these steps −fre := a list containing frequencies of each elements present in concatenated string of s and tfor each cnt in ... Read More

Program to check sum of two numbers is up to k from sorted List or not in Python

Arnab Chakraborty
Updated on 14-Oct-2021 10:32:25

623 Views

Suppose we have a list of numbers called nums and the elements in nums are sorted in ascending order. We also have another value k, we have to check whether any two elements taken from the list add up to k or not. The numbers can also be negative or 0. We have to solve this problem in constant amount of space usage.So, if the input is like nums = [-8, -3, 2, 7, 9] k = 4, then the output will be True, because if we take 7 and -3, then the sum is 7 + (-3) = 4, ... Read More

Program to find sum of two numbers which are less than the target in Python

Arnab Chakraborty
Updated on 14-Oct-2021 10:29:01

725 Views

Suppose we have a list of numbers called nums and also have a target value, we have to find the sum of the largest pair of numbers in nums whose sum is at most (target-1).So, if the input is like nums = [8, 3, 4, 9, 2] target = 8, then the output will be 7, because the sum of the largest pair of numbers less than 8 is 4 + 3 = 7.To solve this, we will follow these steps −sort the list numsp1 := 0p2 := size of nums - 1m := -infwhile p1 < p2, doif nums[p1] ... Read More

Program to create data structure to check pair sum is same as value in Python

Arnab Chakraborty
Updated on 14-Oct-2021 10:24:49

119 Views

Suppose we want to make a data structure that has two methods −add(val) this adds the value val to the data structurefind(val) this checks whether there are two elements whose sum is val or notWe have to design this so that we can get the result on the fly. We will not search for numbers every time when a query comes.So, if the input is like create an object obj and add few numbers 6, 14, 3, 8, 11, 15, then check like obj.find(9), obj.find(11), obj.find(15), then the output will be True, True, False as 9 can be formed with ... Read More

Program to check typed string is for writing target string in stuck keyboard keys or not in Python

Arnab Chakraborty
Updated on 14-Oct-2021 10:19:08

186 Views

Suppose we have two strings s and t. We want to form t, but there are some problems in the keyboard where some of characters stuck so they may be written 1 or more times. We have to check whether it's possible that typed s was meant to write t or not.So, if the input is like s = "appppleee" t = "apple", then the output will be True.To solve this, we will follow these steps −i := 0, j := 0s_len := size of st_len := size of tt_last := blank stringwhile j < t_len, doif i is same ... Read More

Advertisements