AmitDiwan has Published 10744 Articles

Python – How to check missing dates in Pandas

AmitDiwan

AmitDiwan

Updated on 09-Sep-2021 11:13:53

2K+ Views

To check missing dates, at first, let us set a dictionary of list with date records i.e. Date of Purchase in our example −# dictionary of lists d = {'Car': ['BMW', 'Lexus', 'Audi', 'Mercedes', 'Jaguar', 'Bentley'],    'Date_of_purchase': ['2020-10-10', '2020-10-12', '2020-10-17', '2020-10-16', '2020-10-19', '2020-10-22']}Now, create a dataframe from the above ... Read More

How to do Fuzzy Matching on Pandas Dataframe Column Using Python?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2021 10:32:35

2K+ Views

We will match words in the first DataFrame with words in the second DataFrame. For closest matches, we will use threshold. We took the value of threshold as 70 i.e., match occurs when the strings at more than 70% close to each other.Let us first create Dictionaries and convert to ... Read More

How to count frequency of itemsets in Pandas DataFrame

AmitDiwan

AmitDiwan

Updated on 09-Sep-2021 08:47:43

321 Views

Use the Series.value_counts() method to count frequency of itemsets. At first, let us create a DataFrame −# Create DataFrame dataFrame = pd.DataFrame({'Car': ['BMW', 'Mercedes', 'Lamborghini', 'Audi', 'Mercedes', 'Porsche', 'Lamborghini', 'BMW'], 'Place': ['Delhi', 'Hyderabad', 'Chandigarh', 'Bangalore', 'Hyderabad', 'Mumbai', 'Mumbai', 'Pune'], 'UnitsSold': [95, 80, 80, 75, ... Read More

How to add column from another DataFrame in Pandas?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2021 07:08:56

6K+ Views

The insert() method is used to add a column from another DataFrame. At first, let us create our first DataFrame −dataFrame1 = pd.DataFrame({"Car": ["Audi", "Lamborghini", "BMW", "Lexus"],    "Place": ["US", "UK", "India", "Australia"],    "Units": [200, 500, 800, 1000]})Now, let us create our second DataFrame −dataFrame2 = pd.DataFrame({"Model": [2018, 2019, ... Read More

How to do groupby on a multiindex in Pandas?

AmitDiwan

AmitDiwan

Updated on 09-Sep-2021 06:23:53

349 Views

Multiindex Data Frame is a data frame with more than one index. Let’s say the following is our csv stored on the Desktop −At first, import the pandas library and read the above CSV file −import pandas as pd df = pd.read_csv("C:/Users/amit_/Desktop/sales.csv") print(df)We will form the ‘Car‘ and ‘Place‘ ... Read More

Python program to find Most Frequent Character in a String

AmitDiwan

AmitDiwan

Updated on 09-Sep-2021 06:14:20

4K+ Views

When it is required to find the most frequent character in a string, an empty dictionary is created, and the elements in the string are iterated over. When a character is found in the dictionary, it is increment, else it is assigned to 1. The maximum of the values in ... Read More

Python program to find the Decreasing point in a List

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 10:50:40

225 Views

When it is required to find the decreasing point in a list, a simple iteration and the ‘break’ statement are used.ExampleBelow is a demonstration of the same −my_list = [21, 62, 53, 94, 55, 66, 18, 1, 0] print("The list is :") print(my_list) my_result = -1 for index ... Read More

Python - Unique keys count for Value in Tuple List

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 10:49:19

316 Views

When it is required to get the count of the unique values in a list of tuple, ‘defaultdict’, ‘set’ operator and the ‘append’ method are used.ExampleBelow is a demonstration of the same −from collections import defaultdict my_list = [(12, 32), (12, 21), (21, 32), (89, 21), (71, 21), (89, ... Read More

Python – Sort by Rear Character in Strings List

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 10:47:33

167 Views

When it is required to sort the list by rear character, a method is defined that uses negative indexing to return the result.ExampleBelow is a demonstration of the same −def get_rear_position(element):    return element[-1] my_list = ['python', 'is', 'fun', 'to', 'learn'] print("The list is : ") print(my_list) ... Read More

Python – Sort Matrix by None frequency

AmitDiwan

AmitDiwan

Updated on 08-Sep-2021 10:46:16

147 Views

When it is required to sort a matrix by ‘None’ frequency, a method is defined that takes a parameter and uses list comprehension, ‘not’ operator and ‘len’ method to determine the result.ExampleBelow is a demonstration of the same −def get_None_freq(row):    return len([element for element in row if not element]) ... Read More

Advertisements