Found 26504 Articles for Server Side Programming

How to convert character column of a matrix into numeric in R?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:19:54

3K+ Views

If we have a matrix that contains character columns and we want to convert a single column to numeric then we first need to convert the matrix into a data frame using as.data.frame function after that as.numeric function can be used to change the particular column to numeric type as shown in the below examples.Example 1Following snippet creates a matrix −M1

How to find the average of a particular column in R data frame?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:12:53

14K+ Views

To find the average of a particular column in R data frame, we can take the help of delta ($) operator.For example, if we have a data frame called df that contains a column x then we can find the average of column x by using the command given below −mean(df$x)Example 1Following snippet creates a sample data frame −x1

How to find the mean of all matrices stored in an R list?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:08:25

420 Views

To find the mean of all matrices stored in an R list, we can use sapply function along with mean function. For example, if we have a list called LIST that contains some matrices then the mean of each matrix can be found by using the command given below −sapply(LIST,mean)Check out the below given example to understand how it works.ExampleFollowing snippet creates a list of matrices −M1

How to update single value in an R data frame?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:04:37

3K+ Views

To update single value in an R data frame, we can use row and column indices with single square brackets.For example, if we have a data frame called df that contains two columns and ten rows and if we want to change the fifth value in second column to 10 then we can use the command given below −df[5,2]

How to find the coordinate of a value in an R matrix?

Nizamuddin Siddiqui
Updated on 22-Nov-2021 07:00:27

2K+ Views

The coordinate of a value in an R matrix is the row and column intersection that is the row and column index for that particular value. This can be found by using which function.For example, if we have a matrix called M that contains value starting from 1 to 20 then we can find the coordinate of value 5 by using the command given below − which(M==5,arr.ind=TRUE)ExampleFollowing snippet creates a matrix −M1

What does agg() method do in pandas series?

Gireesha Devara
Updated on 18-Nov-2021 10:43:20

341 Views

The agg() method in pandas Series is used to apply one or more functions on a series object. By using this agg() method we can apply multiple functions at a time on a series.To use multiple functions at once we need to send those function names as a list of elements to the agg() function.Example# import pandas package import pandas as pd # create a pandas series s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) print(s) # Applying agg function result = s.agg([max, min, len]) print('Output of agg method', result)ExplanationThe object “s” has 10 ... Read More

How to suffix a string to pandas series index labels?

Gireesha Devara
Updated on 18-Nov-2021 10:36:49

508 Views

The add_suffix is the panda Series function which is used to add a string suffix to the series index labels. this method will return a new series object with updated labels.This add_suffic method takes a string as a parameter, and using that string will update the series labels. It will add the given string after the index labels of the series.Example# import pandas package import pandas as pd # create a pandas series s = pd.Series([2, 4, 6, 8, 10]) print(series) result = s.add_suffix('_Index') print("Resultant series with updated labels: ", result)ExplanationIn this following example, we created a series ... Read More

How to add two pandas Series objects by handling None values?

Gireesha Devara
Updated on 18-Nov-2021 10:33:29

677 Views

In pandas Series functionalities we have a function called add() which is used to add a series object with another series object. It is also used to add a Series object with an integer value and with a python list.The series.add() method has a fill_values parameter. Which is used to handle the missing values effectively by substituting a float value to this parameter. By default the input to this fill_value parameter is Nan.Exampleimport pandas as pd import numpy as np sr1 = pd.Series(np.arange(1, 6)) print('Series Object 1:', sr1, sep='') sr2 = pd.Series(np.random.randint(10, 20, 4)) print('Series Object 2:', ... Read More

What does the add() method do in the pandas series?

Gireesha Devara
Updated on 18-Nov-2021 10:25:12

335 Views

The basic operation of this add() method in series is used to add a series with another series, or with a list of values, or with a single integer. And it will return a new series with resultant elements.It supports the substitution of fill_values for handling missing data. We can fill Nan Values using the fill_value parameter of the series.add() method.If you want to add a series with a list, then the elements in the list must be equal to the number of elements in the series.Example# import the required packages import pandas as pd import numpy as np ... Read More

How can we detect duplicate labels using the Python Pandas library?

Gireesha Devara
Updated on 18-Nov-2021 10:22:30

620 Views

Pandas used to deal with large data sets, in that large data tables columns and rows are indexed with some names and those names are called labels. When we are working with datasets there may be some duplicate labels present in the data set.The duplication can lead to making incorrect conclusions on our data, it may impact our desired outputs. Here we are talking about label duplication, nothing but rows and column index names repeated more than 1 time.Let’s take an example to identify the duplicate labels in a DataFrame.Identifying duplicates in column labelsExampledf1 = pd.DataFrame([[6, 1, 2, 7], [8, ... Read More

Advertisements