Found 507 Articles for Pandas

How to drop duplicate rows in pandas series?

Gireesha Devara
Updated on 04-Mar-2022 07:52:04

849 Views

The main advantage of using the pandas package is analysing the data for Data Science and Machine Learning applications. In the process of analysing the data, deleting duplicate values is a commonly used data cleaning task.To remove duplicate values from a pandas series object, we can use the drop_duplicate() method. This method returns a series with deleted duplicate rows, and it won’t alter the original series object. Instead, it will return a new one.By using the inplace parameter, we can update the changes into the original series object by setting “inplace=True”.The other important parameter in the drop_duplicates() method is “Keep”. ... Read More

What does agg() method do in pandas series?

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

246 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

386 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

524 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

252 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

479 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

What are stack and unstack functions in the Python Pandas library.

Gireesha Devara
Updated on 18-Nov-2021 10:19:47

1K+ Views

Stack and unstack functions are used to reshape a DateFrame in the pandas library to extract more information in different ways.StackPandas stack is used for stacking the levels from column to index. It returns a new DataFrame or Series with a multi-level index. The stack method has 2 parameters which are level and dropna.The level parameter is used to stack from the column axis onto the index axis, the default value is 1, and we can give string, list, and integer. As well as dropna is used to remove rows in the resultant DataFrame/Series with missing values. By default it ... Read More

How to concrete a single Series into a string Python Pandas library?

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

1K+ Views

Using pandas.Series.to_string() we can convert a single series into a string.Let’s take some examples and see how it’s gonna work.ExampleCreate a pandas Series using string dtype data, then convert it to a string.# create a series ds = pd.Series(["a", "b", "c", "a"], dtype="string") print(ds) # display series s = ds.to_string() # convert to string print() print(repr(s)) display converted outputExplanationThe variable ds holds a pandas Series with all string data by defining dtype as a string. Then convert the series into a string by using the pandas.Series.to_string method, here we define it as ds.to_string(). Finally, the converted string is assigned to ... Read More

How do StringDtype objects differ from object dtype in Python Pandas?

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

568 Views

Pandas can not only include text data as an object, it also includes any other data that pandas don’t understand. This means, if you say when a column is an Object dtype, and it doesn’t mean all the values in that column will be a string or text data. In fact, they may be numbers, or a mixture of string, integers, and floats dtype. So with this incompatibility, we can not do any string operations on that column directly.Due to this problem, string dtype is introduced from the pandas 1.0 version, but we need to define it explicitly.See some examples ... Read More

What are various Text data types in Python pandas?

Gireesha Devara
Updated on 18-Nov-2021 10:02:57

334 Views

There are two ways to store textual data in python pandas (for version 1.0.0.to Latest version 1.2.4). On this note, we can say pandas textual data have two data types which are object and StringDtype.In the older version of pandas (1.0), only object dtype is available, in a newer version of pandas it is recommended to use StringDtype to store all textual data. To overcome some disadvantages of using objects dtype, this StringDtype is introduced in the pandas 1.0 version. Still, we can use both object and StringDtype for text data.Let’s take an example, in that create a DataFrame using ... Read More

Advertisements