Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 345 of 855
Program to find minimum deletion cost to avoid repeating letters in Python
Suppose we have a string s and another array of integers called cost where cost[i] represents the cost of deleting the ith character in s. We have to find the minimum cost of deletions such that there are no two same letters next to each other. We have to keep in mind that we will delete the chosen characters at the same time. So after deleting a character, the costs of deleting other characters will not change. So, if the input is like s = "pptpp", cost = [2, 3, 4, 5, 2], then the output will be 4 ...
Read MoreProgram to find number of ways where square of number is equal to product of two numbers in Python
Suppose we have two arrays nums1 and nums2, we have to find the number of triplets formed (type 1 and type 2) following these two rules − Triplet (i, j, k) if nums1[i]^2 = nums2[j] * nums2[k] where [0
Read MoreProgram to find shortest subarray to be removed to make array sorted in Python
Given an array, we need to find the shortest subarray to remove so that the remaining elements are in non-decreasing (sorted) order. This problem involves finding the longest possible sorted subsequence that can be formed by keeping elements from both ends of the array. So, if the input is like arr = [10, 20, 30, 100, 40, 20, 30, 50], then the output will be 3 because we can remove [100, 40, 20] which is the smallest subarray of length 3, and by removing these all remaining elements are in non-decreasing order [10, 20, 30, 30, 50]. Algorithm ...
Read MorePython - Density Plots with Pandas for a specific attribute
A density plot shows the probability density function of a continuous variable. In Pandas, you can create density plots using the plot.density() method to visualize the distribution of numerical data. What is a Density Plot? A density plot is a smoothed version of a histogram that shows the distribution of values in a dataset. It's useful for understanding the shape, central tendency, and spread of your data. Creating Sample Data Let's create a sample dataset with age information to demonstrate density plotting ? import pandas as pd import matplotlib.pyplot as plt import numpy as ...
Read MorePython Pandas - Draw a vertical violinplot grouped by a categorical variable with Seaborn
A violin plot combines a box plot with a kernel density estimate to show the distribution of data. Seaborn's violinplot() function creates violin plots grouped by categorical variables, making it perfect for comparing distributions across different categories. Understanding Violin Plots Violin plots display: Distribution shape − The width shows density at different values Quartiles − Like a box plot, showing median and quartiles Data range − The full extent of the data Creating Sample Data Let's create a dataset similar to cricket player data to demonstrate violin plots − import seaborn as ...
Read MorePython Pandas- Create multiple CSV files from existing CSV file
Pandas provides powerful functionality to split CSV files into multiple files based on specific columns. This is useful when you need to segregate data by categories, such as creating separate files for different car brands, departments, or regions. SalesRecords.csv Car | Date_of_Purchase BMW | 10/10/2020 Lexus | 10/12/2020 BMW | 10/17/2020 Jaguar | 10/16/2020 ...
Read MoreProgram to find maximum length of subarray with positive product in Python
When working with arrays containing positive and negative numbers, we often need to find the maximum length of a subarray where the product of all elements is positive. A product is positive when there's an even number of negative values in the subarray. So, if the input is like nums = [2, -2, -4, 5, -3], then the output will be 4 because the first four elements [2, -2, -4, 5] form a subarray with product 2×(-2)×(-4)×5 = 80, which is positive. Algorithm Approach To solve this problem, we need to ? Split the array ...
Read MoreHow to Merge all CSV Files into a single dataframe – Python Pandas?
Merging multiple CSV files into a single DataFrame is a common task in data analysis. Python provides the glob module to find files matching patterns, and Pandas concat() to combine them efficiently. Using os.path.join() and glob Direct glob pattern matching Merging files in specific order ...
Read MoreProgram to find out the greatest subarray of a given length in python
Suppose we have an array containing various integer values and a given length k. We have to find out the greatest subarray from the array of the given length. A subarray is said to be greater than another subarray if at the first differing position, the first subarray has a larger element than the second subarray. So, if the input is like nums = [5, 3, 7, 9], k = 2, then the output will be [7, 9]. Algorithm To solve this, we will follow these steps ? start := size of nums − k ...
Read MoreHow to Sort CSV by multiple columns in Python ?
In Python, to sort a CSV file by multiple columns, we can use the sort_values() method provided by the Python Pandas library. This method sorts DataFrame values by taking column names as arguments. Common methods for sorting a CSV file by multiple columns include ? sort_values() with inplace − Sort DataFrame by multiple columns, modifying the original sort_values() without inplace − Sort DataFrame by multiple columns, ...
Read More