AmitDiwan has Published 10744 Articles

Python - Given a list of integers that represents a decimal value, increment the last element by 1

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:15:57

479 Views

When it is required to increment the last element by 1 when a decimal value is given an input, a method named ‘increment_num’ is defined that checks to see if the last element in the list is less than 9. Depending on this, operations are performed on the elements of ... Read More

Python - Merge Pandas DataFrame with Left Outer Join

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:14:50

2K+ Views

To merge Pandas DataFrame, use the merge() function. The left outer join is implemented on both the DataFrames by setting under the “how” parameter of the merge() function i.e. −how = “left”At first, let us import the pandas library with an alias −import pandas as pd Let’s create two DataFrames ... Read More

Python - Given an integer 'n', check if it is a power of 3, and return True, otherwise False.

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:13:54

733 Views

When it is required to check if a given variable is of power 3, a method named ‘check_power_of_3’ is defined that takes an integer as parameter. The modulus operator and the ‘//’ operator is used to check for the same and return True or False depending on the output.ExampleBelow is ... Read More

Python - Given an integer 'n', check if it is a power of 4, and return True, otherwise False.

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:11:57

832 Views

When it is required to check if a given variable is of power 4, a method named ‘check_power_of_4’ is defined that takes an integer as parameter. The modulus operator and the ‘//’ operator is used to check for the same and return True or False depending on the output.ExampleBelow is ... Read More

Python - Check if two strings are isomorphic in nature

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:08:09

369 Views

When it is required to check if two strings are isomorphic in nature, a method is defined that takes two strings as parameters. It iterates through the length of the string, and converts a character into an integer using the ‘ord’ method.ExampleBelow is a demonstration of the sameMAX_CHARS = 256 ... Read More

Python Pandas – Remove numbers from string in a DataFrame column

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:07:42

3K+ Views

To remove numbers from string, we can use replace() method and simply replace. Let us first import the require library −import pandas as pdCreate DataFrame with student records. The Id column is having string with numbers −dataFrame = pd.DataFrame(    {       "Id": ['S01', 'S02', 'S03', 'S04', 'S05', ... Read More

Python - Check if a number and its double exists in an array

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:03:26

560 Views

When it is required to check if a number and its double exists in an array, it is iterated over, and multiple with 2 and checked.ExampleBelow is a demonstration of the samedef check_double_exists(my_list): for i in range(len(my_list)): for j in (my_list[:i]+my_list[i+1:]): ... Read More

Python - Find the number of prime numbers within a given range of numbers

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:01:52

2K+ Views

When it is required to find the prime numbers within a given range of numbers, the range is entered and it is iterated over. The ‘%’ modulus operator is used to find the prime numbers.ExampleBelow is a demonstration of the samelower_range = 670 upper_range = 699 print("The lower and upper ... Read More

Python Pandas - Display unique values present in each column

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 11:00:41

542 Views

To display unique values in each column, use the unique() method and set the column within it. At first, import the required library −import pandas as pdCreate a DataFrame with two columns and duplicate records −dataFrame = pd.DataFrame(    {       "Student": ['Jack', 'Robin', 'Ted', 'Robin', 'Scarlett', 'Kat', ... Read More

Python - Given an integer list, find the third maximum number if it exists

AmitDiwan

AmitDiwan

Updated on 20-Sep-2021 10:59:47

381 Views

When it is required to find the third maximum in a list of integers, a method is defined that takes a list as a parameter. It initializes a list of floating point numbers to infinity. The values in the list are iterated over, and compared with infinite values. Depending on ... Read More

Advertisements