Found 507 Articles for Pandas

What is the basic operation of pandas Series.factorize() function?

Gireesha Devara
Updated on 07-Mar-2022 07:13:36

122 Views

The pandas Series.factorize() method is used to encode the series object as an enumerated type or categorical variable. This method generates the numeric representation of the series data.The output of this Series.factorize() method is a tuple and it has two elements one is indicating codes and another element indicates uniques.Example 1In the following example, we will see how the series.factorize() method encodes the elements of the series object.# importing pandas package import pandas as pd # create a series s = pd.Series({'A':"aa", 'B':"bb", "C":"cc"}) print(s) result = s.factorize() print(result)ExplanationHere the series object is created by using a python ... Read More

How to unnest (explode) a row in a pandas series?

Gireesha Devara
Updated on 07-Mar-2022 07:10:17

1K+ Views

If some of the elements in the series object have lists, then we can unnest those list elements into multiple rows of the series object. Unnesting is nothing but exploding the lists into rows.So this transformation can be done easily with the help of the pandas series.explode() method. This method is used to transform list-like elements of a series object into rows, and the index will be duplicated for these rows.The ignore_index is the only parameter for this method and it takes boolean values, False is the default one, and True means the resulting index will be labeled from 0 ... Read More

How does the pandas series.equals() method handle the null values?

Gireesha Devara
Updated on 07-Mar-2022 07:03:26

2K+ Views

It is very common to have missing values in a series object, and if you want to compare that type of series objects then the ordinary comparison does not work because nan != nan, In that case, we can use the equals() method. The equals() method considers Nan’s in the same location to be equal.The fundamental operation of the pandas series.equals() method is used to compare two series for equality. it returns True if the two series have the same elements and shape, and returns False if the two series are unequal.Example 1In the following example, two series objects series1 ... Read More

What is the basic operation of the series.equals() method in pandas?

Gireesha Devara
Updated on 07-Mar-2022 07:00:08

91 Views

The basic operation of the series.equals() method in the pandas constructor is used to test whether the elements in two series objects are the same or not, and it also compares the shape of the two series object.The equals() method is very similar to the pandas series.eq() method but the difference is it will return a boolean value as a result, whereas the eq() method returns a series object with boolean values.The output boolean value True indicates the elements in two series objects are the same. And it indicates False for unequal elements in series objects.Example 1In the following example, ... Read More

How to handle the null values while comparing the two series objects using series.eq() method?

Gireesha Devara
Updated on 07-Mar-2022 06:54:36

389 Views

The Pandas series.eq() method is used to compare every element of a given series with a passed parameter (other series object or a scalar value). It will return True for every element which is equal to the element in the other series object (passed series object).The output of the eq() method is a series with boolean values and it performs an element-wise comparison operation which is nothing but caller series = other series. In the resultant series, the True value indicates the equivalent value in the other series object as well as, the False value indicates an unequal value.Handling of ... Read More

What is the basic operation of the series.eq() method in pandas?

Gireesha Devara
Updated on 07-Mar-2022 06:46:48

88 Views

The series.eq() method in the pandas constructor is used to compare elements of the given series with others (maybe another series or a scalar value). As a result, It will return a new series object with boolean values.The element-wise equal operation is done by using this eq() method. The boolean value True represents the equivalent value in the second series object. And remaining unequal values are represented by the boolean value False.The parameters of the eq() method are other, fill_value, and level.Example 1In the following example, we will see how the eq() method compares elements of a series object with ... Read More

How to remove rows in a Pandas series with duplicate indices?

Gireesha Devara
Updated on 07-Mar-2022 06:20:05

2K+ Views

By using the duplicated() method in the pandas series constructor we can easily identify the duplicate values in the index of a series object. The method duplicated() is used to identify the duplicate values in a series object.The duplicated() method will return a series with boolean values. Boolean value False indicates single occurrence values mean unique values. The duplicated values are indicated with boolean value True.Example 1Here we will see how we can delete the rows of a series object with duplicate indices.# importing pandas package import pandas as pd #create series series = pd.Series(["a", "b", "c", "d", "e"], ... Read More

What is the use of the series.duplicated() method in pandas?

Gireesha Devara
Updated on 07-Mar-2022 06:15:48

96 Views

Finding the duplicate values in an object is a very common task in the data analysis process. In pandas, we have a function called duplicated() which is used to identify the duplicate values.For a pandas series object, the duplicated() method will return a series with boolean values. True indicates duplicate values only for the last occurrence values or the first occurrence values or it may indicate all the duplicate values.The duplicated() method has a parameter called “keep” which is used to treat the duplicate values differently. The default behavior of this parameter is “first” which means it marks all the ... Read More

What are the ways to extract features from a DateTime variable using pandas?

Gireesha Devara
Updated on 07-Mar-2022 06:11:34

226 Views

Reading and extracting valid information from a DateTime object is a very important task in data analysis. The pandas package provides some useful tools to perform feature extracting from a DateTime object.In pandas, the series.dt() method is used to access the components like years, months, days, etc., from a given time series.The series.dt() method has some attributes to extract the year, month, quarter, and day features. In the examples given below, we will use some of these attributes to extract features.Example 1You can see that we have created a pandas series with 10 different timestamps. Then, we accessed only the ... Read More

How does the keep parameter work in the pandas series.drop_duplicates() method?

Gireesha Devara
Updated on 04-Mar-2022 08:03:29

370 Views

The drop_duplicate() method in the pandas series constructor is used to remove the duplicate values from a series object. This method cleans the duplicate values and returns a series with modified rows, and it won’t alter the original series object. Instead, it will return a new one.One of the important parameters in the drop_duplicates() method is “Keep”, the default value of this parameter is “first” which keeps the first occurrence value and deletes the remaining. We can also specify Last and False values to the keep parameter.If keep=False, it will delete all duplicate values. Or if keep= “Last”, it deletes ... Read More

Advertisements