Python – Convert Suffix denomination to Values

AmitDiwan
Published on 16-Sep-2021 09:21:11
When it is required to convert the suffix denomination to values, the dictionary is iterated over and the ‘replace’ method is used to convert them to values.ExampleBelow is a demonstration of the samemy_list = ["5Cr", "7M", "9B", "12L", "20Tr", "30K"] print("The list is :") print(my_list) value_dict = {"M": 1000000, ... Read More

Python Pandas - How to select rows from a DataFrame by passing row label

AmitDiwan
Published on 16-Sep-2021 09:12:58
To select rows by passing a label, use the loc() function. Mention the index of which you want to select the row. This is the index label in our example. We have x, y and z as the index label and can be used to select rows with loc().Create a ... Read More

Python - Cast datatype of only a single column in a Pandas DataFrame

AmitDiwan
Published on 16-Sep-2021 09:01:31
To cast only a single column, use the astype() method. Let us first create a DataFrame with 2 columns. One of them is a “float64” type and another “int64” −dataFrame = pd.DataFrame( { "Reg_Price": [7000.5057, 1500, 5000, 8000, 9000.75768, 6000], ... Read More

Python – Check Similar elements in Matrix rows

AmitDiwan
Published on 16-Sep-2021 09:09:50
When it is required to check for similar elements in a matrix row, a method is defined that take a matrix as parameter. The map method is used to covert the matrix to a tuple. The matrix values are iterated over and if the frequency is greater than 1, it ... Read More

Python – Check alternate peak elements in List

AmitDiwan
Published on 16-Sep-2021 08:55:30
When it is required to check the alternate peak elements in a list, a function is defined that iterates through the list, the adjacent elements of the array are compared and depending on this, the output is displayed on the console.ExampleBelow is a demonstration of the samedef find_peak(my_array, array_length) : ... Read More

Python – Extract Paired Rows

AmitDiwan
Published on 16-Sep-2021 08:52:55
When it is required to extract paired rows, a list comprehension and the ‘all’ operator is used.ExampleBelow is a demonstration of the samemy_list = [[10, 21, 34, 21, 37], [41, 41, 52, 68, 68, 41], [12, 29], [30, 30, 51, 51]] print("The list is :") print(my_list) my_result = ... Read More

Python – All replacement combination from other list

AmitDiwan
Published on 16-Sep-2021 08:51:09
When it is required to get the replacement combination from the other list, the ‘combinations’ method and the ‘list’ method is used.ExampleBelow is a demonstration of the samefrom itertools import combinations my_list = [54, 98, 11] print("The list is :") print(my_list) replace_list = [8, 10] my_result ... Read More

Python - Convert one datatype to another in a Pandas DataFrame

AmitDiwan
Published on 16-Sep-2021 08:55:23
Use the astype() method in Pandas to convert one datatype to another. Import the required library −import pandas as pdCreate a DataFrame. Here, we have 2 columns, “Reg_Price” is a float type and “Units” int type −dataFrame = pd.DataFrame( { "Reg_Price": ... Read More

Python - Sort rows by Frequency of K

AmitDiwan
Published on 16-Sep-2021 08:49:13
When it is required to sort the rows by frequency of ‘K’, a list comprehension and ‘Counter’ methods are used.ExampleBelow is a demonstration of the samefrom collections import Counter my_list = [34, 56, 78, 99, 99, 99, 99, 99, 12, 12, 32, 51, 15, 11, 0, 0] print ... Read More

Python - Selective consecutive Suffix Join

AmitDiwan
Published on 16-Sep-2021 08:47:24
When it is required to find the selective consecutive suffix join, a simple iteration, the ‘endswith’ method and the ‘append’ method can be used.ExampleBelow is a demonstration of the samemy_list = ["Python-", "fun", "to-", "code"] print("The list is :") print(my_list) suffix = '-' print("The suffix is :") print(suffix) ... Read More
Advertisements