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
Articles on Trending Technologies
Technical articles with clear explanations and examples
Write a program in Python to replace all odd index position in a given series by random uppercase vowels
Input − Assume, you have a Series, 0 1 1 2 2 3 3 4 4 5Output −And, the result after replacing odd index with uppercase vowels as follows −0 1 1 A 2 3 3 U 4 5SolutionDefine a Series.Define uppercase alphabetsCreate lambda filter method and replace vowels in all index positions. It is defined belowvowels = re.findall(r'[AEIOU]', chars) result = pd.Series(filter(lambda x: r.choice(vowels) if(x%2!=0), l)data)Exampleimport pandas as pd import random as r l = [1, 2, 3, 4, 5] data = pd.Series(l) print(“Given series:”, data) vowels = list("AEIOU") ...
Read MoreWrite a program in Python to filter only integer elements in a given series
Input − Assume you have the following series −0 1 1 2 2 python 3 pandas 4 3 5 4 6 5Output − The result for only integer elements are −0 1 1 2 4 3 5 4 6 5Solution 1Define a Series.Apply lambda filter method inside a regular expression to validate digits and expression accepts only strings so convert all the elements into strings. It is defined below, data = pd.Series(ls) result = pd.Series(filter(lambda x:re.match(r"\d+", str(x)), data))Finally, check the values using the isin() function.ExampleLet us ...
Read MoreWrite a program in Python to check if a series contains duplicate elements or not
Input − Assume, you have the following series, 0 1 1 2 2 3 3 4 4 5The above series contains no duplicate elements. Let’s verify using the following approaches.Solution 1Assume, you have a series with duplicate elements0 1 1 2 2 3 3 4 4 5 5 3Set if condition to check the length of the series is equal to the unique array series length or not. It is defined below, if(len(data)==len(np.unique(data))): print("no duplicates") else: print("duplicates found")Exampleimport pandas as pd import numpy as np data = ...
Read MoreFinding three elements with required sum in an array in JavaScript
We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should then pick three such numbers from the array, (if they exist) whose sum is equal to the number specified by the second argument.The function should finally return an array of arrays of all such triplets if they exist, an empty array otherwise.For example −If the input array and the number is −const arr = [2, 5, 7, 8, 9, 11, 1, 6]; const sum = 22;Then the output should be ...
Read MorePython program to filter perfect squares in a given series
Input −Assume you have a series, 0 14 1 16 2 30 3 49 4 80Output −The result for perfect square elements are, 0 4 1 16 3 49Solution 1We can use regular expression and lambda function filter method to find the perfect square values.Define a Series.Apply lambda filter method to check the value is a perfect square or not. It is defined below, l = [14, 16, 30, 49, 80] data=pd.Series([14, 16, 30, 49, 80]) result =pd.Series(filter(lambda x: x==int(m.sqrt(x)+0.5)**2, l))Finally, check the list of values to the series ...
Read MoreDetermining beautiful number string in JavaScript
A numeric string, str, is called a beautiful string if it can be split into a sequence arr of two or more positive integers, satisfying the following conditions −arr[i] - arr[i - 1] = 1, for any i in the index of sequence, i.e., each element in the sequence is more than the previous element.No element of the sequence should contain a leading zero. For example, we can split '50607' into the sequence [5, 06, 07], but it is not beautiful because 06 and 07 have leading zeros.The contents of the sequence cannot be rearranged.For example −If the input string ...
Read MoreHow to Plot Cluster using Clustermaps class in Matplotlib
Let us suppose you have given a dataset with various variables and data points thus in order to plot the cluster map for the given data points we can use Clustermaps class.In this example, we will import the wine quality dataset from the https://archive.ics.uci.edu/ml/datasets/wine+quality.import matplotlib.pyplot as plt import numpy as np import seaborn as sns sns.set(style='white') #Import the dataset wine_quality = pd.read_csv(‘winequality-red.csv’ delimeter=‘;’)Let us suppose we have raw data of wine Quality datasets and associated correlation matrix data.Now let us plot the clustermap of the data, row_colors = wine_quality["quality"].map(dict(zip(wine_quality["quality"].unique(), "rbg"))) g = sns.clustermap(wine_quality.drop('quality', axis=1), standard_scale=1, robust=True, row_colors=row_colors, cmap='viridis')Plot the ...
Read MoreLargest Merge of Two Strings in Python
Let us suppose we have two strings 'a' and 'b' and a string 'merge'. The task is to fill the string 'merge' with the characters from 'a' and 'b' in such a way that, If the string 'a' is non-empty, then remove the first character from the string 'a' and copy it into string 'merge'.If the string 'b' is non-empty, then remove the first character from the string 'b' and copy it into string 'merge'.If the strings 'a' and 'b' are non-empty, then remove the first characters from string 'a' and copy it into string 'merge' and then remove the ...
Read MoreHow to align multiple plots in a grid using GridSpec Class in Matplotlib
Aligning the multiple plots in a grid can be very messy and it can create multiple issues like higher width and height or minimal width to align all the plots. In order to align all the plots in a grid, we use GridSpec class.Let us suppose that we have a bar graph plot and we want to align the symmetry of the plot in this sample.First Import all the necessary libraries and plot some graphs in two grids. Then, we will plot a constant error bar and a symmetric and asymmetric error bar on the first grid. In the second ...
Read MorePlotting regression and residual plot in Matplotlib
To establish a simple relationship between the observations of a given joint distribution of a variable, we can create the plot for the regression model using Seaborn.To fit the dataset using the regression model, we have to first import the necessary libraries in Python.We will create plots for each regression model, (a) Linear Regression, (b) Polynomial Regression, and (c) Logistic Regression.In this example, we will use the wine quality dataset which can be accessed from here, https://archive.ics.uci.edu/ml/datasets/wine+qualityExampleimport matplotlib.pyplot as plt import seaborn as sns from scipy.stats import pearsonr sns.set(style="dark", color_codes=True) #import the dataset wine_quality = pd.read_csv('winequality-red.csv', delimiter=';') #Plotting ...
Read More