Found 26504 Articles for Server Side Programming

How to divide each column by a particular column in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 11:02:17

15K+ Views

To divide each column by a particular column, we can use division sign (/). For example, if we have a data frame called df that contains three columns say x, y, and z then we can divide all the columns by column z using the command df/df[,3].ExampleConsider the below data frame − Live Demox1

How to have logarithmic bins in a Python histogram?

SaiKrishna Tavva
Updated on 23-Sep-2024 14:30:32

5K+ Views

In Python to create a logarithmic bin, we can use Numpy library to generate logarithmically spaced bins, and using matplotlib for creating a histogram. Logarithmic bins in a Python histogram refer to bins that are spaced logarithmically rather than linearly. We can set the logarithmic bins while plotting histograms by using plt.hist(bin="") Steps to Create Logarithmic Bins To set logarithmic bins in a Python histogram, the steps are as follows. Import Libraries: Importing 'matplotlib' for plotting and 'numpy' for performing numerical computations. ... Read More

Changing the color of an axis in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 11:02:31

9K+ Views

First, we can get the axes. Then, ax.spines could help to set the color by specifying the name of the axes, i.e., top, bottom, right and left.StepsAdd an axes to the current figure and make it the current axes.Using step 1 axes, we can set the color of all the axes.Using ax.spines[axes].set_color(‘color’), set the color of the axes. Axes could be bottom, top, right, and left. Color could be yellow, red, black, and blue.To show the figure, use the plt.show() method.Examplefrom matplotlib import pyplot as plt ax = plt.axes() ax.spines['bottom'].set_color('yellow') ax.spines['top'].set_color('red') ax.spines['right'].set_color('black') ax.spines['left'].set_color('blue') plt.show()OutputRead More

How to use regular expressions (Regex) to filter valid emails in a Pandas series?

Prasad Naik
Updated on 16-Mar-2021 11:00:23

792 Views

A regular expression is a sequence of characters that define a search pattern. In this program, we will use these regular expressions to filter valid and invalid emails.We will define a Pandas series with different emails and check which email is valid. We will also use a python library called re which is used for regex purposes.AlgorithmStep 1: Define a Pandas series of different email ids. Step 2: Define a regex for checking validity of emails. Step 3: Use the re.search() function in the re library for checking the validity of the email.Example Codeimport pandas as pd import re ... Read More

Pandas program to convert a string of date into time

Prasad Naik
Updated on 16-Mar-2021 11:02:13

203 Views

In this program, we will convert a date string like "24 August 2020" to 2020-08-24 00:00:00. We will use the to_datetime() function in pandas library to solve this task.AlgorithmStep 1: Define a Pandas series containing date string. Step 2: Convert these date strings into date time format using the to_datetime format(). Step 3: Print the results.Example Codeimport pandas as pd series = pd.Series(["24 August 2020", "25 December 2020 20:05"]) print("Series: ", series) datetime = pd.to_datetime(series) print("DateTime Format: ", datetime)OutputSeries: 0            24 August 2020 1    25 December 2020 20:05 dtype: object DateTime Format: 0   2020-08-24 00:00:00 1   2020-12-25 20:05:00 dtype: datetime64[ns]

Finding the length of words in a given Pandas series

Prasad Naik
Updated on 16-Mar-2021 11:02:49

951 Views

In this task, we will find the length of strings in a Pandas series. We will use the str.len() function in the Pandas library for this purpose.AlgorithmStep 1: Define a Pandas series of string. Step 2: Find the length of each string using the str.len() function. Step 3: Print the results.Example Codeimport pandas as pd series = pd.Series(["Foo", "bar", "London", "Quarantine"]) print("Series: ", series) length = series.str.len() print("Length:", length)OutputSeries: 0           Foo 1           bar 2        London 3    Quarantine dtype: object Length: 0     3 1     3 2     6 3    10 dtype: int64

How to calculate the z score for grouped data in R?

Nizamuddin Siddiqui
Updated on 16-Mar-2021 10:56:35

639 Views

To calculate the z score for grouped data, we can use ave function and scale function. For example, if we have a data frame called df that contains a grouping coloumn say GROUP and a numerical column say Response then we can use the below command to calculate the z score for this data −ave(df$Response,df$GROUP,FUN=scale)ExampleConsider the below data frame − Live Demogrp

Setting Different Bar color in Matplotlib

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:56:01

17K+ Views

We can first create bars and then, by using set_color, we can set the color of the bars.StepsPass two lists consisting of four elements, into the bars method argument.Step 1 returns bars.Return values (0, 1, 2, 3) can be set with different colors, using set_color() method. Green, Black, Red color will be set and one bar will have the default color.To show the figure, use plt.show() method.Examplefrom matplotlib import pyplot as plt bars = plt.bar([1, 2, 3, 4], [1, 2, 3, 4]) bars[0].set_color('green') bars[1].set_color('black') bars[2].set_color('red') plt.show()Output

How to set the current figure in Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:54:16

969 Views

Using the figure() method, we can set the current figure.StepsCreate a new figure, or activate an existing figure, with the window title “Welcome to figure 1”.Create a new figure, or activate an existing figure, with the window title “Welcome to figure 2”.Using plt.show(), show the figures.Examplefrom matplotlib import pyplot as plt plt.figure("Welcome to figure 1") plt.figure("Welcome to figure 2")    # Active Figure plt.show()Output

How to animate a scatter plot in Matplotlib?

Rishikesh Kumar Rishi
Updated on 16-Mar-2021 10:54:57

6K+ Views

Using the FuncAnimation method of matplotlib, we can animate the diagram. We can pass a user defined method where we will be changing the position of the particles, and at the end, we will return plot type.StepsGet the particle's initial position, velocity, force, and size.Create a new figure, or activate an existing figure with figsize = (7, 7).Add an axes to the current figure and make it the current axes, with xlim and ylim.Plot scatter for initial position of the particles.Make an animation by repeatedly calling a function *func*. We can pass a user-defined method that helps to change the ... Read More

Advertisements