Articles on Trending Technologies

Technical articles with clear explanations and examples

Python program to sort tuples by frequency of their absolute difference

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 392 Views

When it is required to sort tuples by frequency of their absolute difference, the lambda function, the abs method and the sorted method are used. This technique sorts tuples based on how often their absolute difference appears in the dataset. Understanding Absolute Difference The absolute difference between two numbers is the positive difference between them. For a tuple (a, b), the absolute difference is abs(a - b). Example Below is a demonstration of sorting tuples by frequency of their absolute difference ? my_list = [(11, 26), (21, 33), (90, 11), (26, 21), (32, 18), ...

Read More

Python Program to Remove First Diagonal Elements from a Square Matrix

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 285 Views

When it is required to remove the first diagonal elements from a square matrix, the enumerate function and list comprehension can be used. The first diagonal (main diagonal) consists of elements where the row index equals the column index. Understanding the Main Diagonal In a square matrix, the main diagonal contains elements at positions (0, 0), (1, 1), (2, 2), and so on. These are the elements we need to remove ? Matrix with Main Diagonal ...

Read More

Python Program to Extract Strings with at least given number of characters from other list

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 188 Views

When you need to extract strings that contain at least a specified number of characters from a given character list, list comprehension provides an efficient solution. This technique counts how many target characters appear in each string and filters based on a minimum threshold. Example Below is a demonstration of extracting strings with at least 2 characters from a specified character list ? my_list = ["Python", "is", "fun", "to", "learn"] print("The list is :") print(my_list) my_char_list = ['e', 't', 's', 'm', 'n'] my_key = 2 print("The value of key is") print(my_key) my_result ...

Read More

Python program to randomly create N Lists of K size

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 339 Views

When you need to generate multiple random lists of a specific size from a larger dataset, Python's random.shuffle() combined with generator functions provides an efficient solution. This approach creates N lists, each containing K randomly selected elements. Using Generator Function with Shuffle Here's how to create a generator that produces random sublists ? from random import shuffle def gen_random_list(my_val, K): while True: shuffle(my_val) yield my_val[:K] my_list = [12, 45, 76, 32, 45, 88, 99, ...

Read More

Python - Count distinct in Pandas Aggregation with Numpy

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 821 Views

To count distinct values in Pandas aggregation, use nunique() method. This tutorial shows how to group by a column, calculate sums using NumPy, and count distinct values simultaneously. Required Libraries Import the necessary libraries for data manipulation ? import pandas as pd import numpy as np Creating Sample DataFrame Create a DataFrame with duplicate values to demonstrate distinct counting ? import pandas as pd import numpy as np dataFrame = pd.DataFrame({ "Car": ['BMW', 'Audi', 'BMW', 'Lexus', 'Lexus'], "Place": ['Delhi', 'Bangalore', 'Delhi', 'Chandigarh', ...

Read More

Python - Remove duplicate values from a Pandas DataFrame

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 819 Views

To remove duplicate values from a Pandas DataFrame, use the drop_duplicates() method. This method identifies rows with identical values across all columns and removes the duplicates, keeping only the first occurrence of each unique row. Creating a DataFrame with Duplicates Let's create a sample DataFrame containing duplicate rows ? import pandas as pd # Create DataFrame with duplicate rows dataFrame = pd.DataFrame({ 'Car': ['BMW', 'Mercedes', 'Lamborghini', 'BMW', 'Mercedes', 'Porsche'], 'Place': ['Delhi', 'Hyderabad', 'Chandigarh', 'Delhi', 'Hyderabad', 'Mumbai'], 'UnitsSold': [95, 70, 80, 95, 70, 90] ...

Read More

Python – Group and calculate the sum of column values of a Pandas DataFrame

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 2K+ Views

In Pandas, you can group DataFrame rows by specific columns and calculate aggregated values like sum, mean, or count. This is particularly useful for analyzing time-series data where you want to group by periods like months, quarters, or years. Creating a Sample DataFrame Let's create a DataFrame with car sales data to demonstrate grouping and summing ? import pandas as pd # Create DataFrame with car sales data dataFrame = pd.DataFrame({ "Car": ["Audi", "Lexus", "Tesla", "Mercedes", "BMW", "Toyota", "Nissan", "Bentley", "Mustang"], "Date_of_Purchase": [ ...

Read More

What are the challenges faced by transport layer protocol?

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2026 7K+ Views

In the OSI (Open System Interconnection) model, the transport layer is the fourth layer responsible for end-to-end communication between sender and receiver over the internet. It provides logical communication and ensures reliable delivery of data packets across the network. Transport Layer Protocols The main transport layer protocols include ? TCP (Transmission Control Protocol) − Connection-oriented, reliable protocol UDP (User Datagram Protocol) − Connectionless, fast protocol SCTP (Stream Control Transmission Protocol) − Message-oriented reliable protocol RDP (Reliable Data Protocol) − Reliable multicast protocol RUDP (Reliable User Datagram Protocol) − UDP with reliability features Responsibilities of ...

Read More

Python Pandas - Generate dates in a range

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 837 Views

Pandas date_range() function generates a sequence of dates within a specified range. This is useful for creating time series data, filtering datasets by date periods, or setting up date indexes for analysis. Syntax pd.date_range(start, end, periods, freq) Parameters The key parameters are: start − Starting date of the range end − Ending date of the range periods − Number of dates to generate freq − Frequency (default is 'D' for daily) Generating Dates with ...

Read More

Python - Compute last of group values in a Pandas DataFrame

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 226 Views

The groupby().last() method in Pandas returns the last row of each group when data is grouped by one or more columns. This is useful for getting the most recent entry for each category in your dataset. Creating Sample Data First, let's create a DataFrame with some sample car sales data ? import pandas as pd dataFrame = pd.DataFrame({ "Car": ['BMW', 'Lexus', 'BMW', 'Tesla', 'Lexus', 'Tesla'], "Place": ['Delhi', 'Bangalore', 'Pune', 'Punjab', 'Chandigarh', 'Mumbai'], "Units": [100, 150, 50, 80, 110, 90] }) print("Original DataFrame:") ...

Read More
Showing 3691–3700 of 61,297 articles
« Prev 1 368 369 370 371 372 6130 Next »
Advertisements