Gireesha Devara

Gireesha Devara

173 Articles Published

Articles by Gireesha Devara

Page 10 of 18

How can we apply an anonymous function to the pandas series?

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 306 Views

The pandas series constructor has an apply() which accepts any user-defined function that applies to the values of the given series object.In the same way, we can apply an anonymous function over a pandas series object. We can use this apply() method on both the pandas data structures DataFrame and Series. It Performs element-wise transformations and returns a new series object as a result.Example 1# import pandas package import pandas as pd import numpy as np # create a pandas series s = pd.Series(np.random.randint(10, 20, 5)) print(s) # Applying an anonymous function result = s.apply(lambda x: x**2) print('Output ...

Read More

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

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 290 Views

The apply() method in pandas Series is used to call our function on a series object. By using this apply() method we can apply our own function on our series object.The apply() method is very similar to some other pandas series methods like agg() and map(). Here the difference is we can apply a function on values of the given series object.Example 1# 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 a function result = s.apply(type) print('Output of apply ...

Read More

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

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 594 Views

The any() is one of the pandas.Series method, which is used to verify if there is any non-zero value present in the given series object.The pandas.Series method “any()” will return a boolean value as an output. It will return True if any value in the given series is non-zero. otherwise, it will return False for all zero values of the given series object.Example 1import pandas as pd # create a series s = pd.Series([False, False]) print(s) print("Output: ") print(s.any())ExplanationLet’s see an example, here we have created a pandas series object with all zero-values (nothing but False). And ...

Read More

What does the pandas.series.values attribute do?

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 819 Views

A pandas series object is used to store 1-dimensional labeled data, that data is called values and the labels are called indexes in pandas.In pandas data structures we can store any kind of data like text data, integer values, and time sequence, and more. We can access series elements by using the respected labels. instead of accessing elements by labels, we can get all elements in a ndarray type object.Example1import pandas as pd # creating a series s = pd.Series([10, 10, 20, 30, 40]) print(s) # Getting values values = s.values print('Output: ') # displaying outputs ...

Read More

How to check whether the Pandas series is having Nan values or not?

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 2K+ Views

To check whether the pandas series object is having null values or not, we can use the “hasans” attribute.The “hasnans” is a pandas attribute that is used to identify if there any null values are present in the given series object. Generally, it returns a boolean output as a result. It returns True if there are anyone or more NaN values, or otherwise, it will return False.This panda “hasnans” property is very similar to the pandas methods like Isnull(), isna(). These methods are used to return an array with boolean values which are used to represent the null values.By using ...

Read More

How to check the data type of a pandas series?

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 17K+ Views

To check the data type of a Series we have a dedicated attribute in the pandas series properties. The “dtype” is a pandas attribute that is used to verify data type in a pandas Series object.This attribute will return a dtype object which represents the data type of the given series.Example 1# importing required packages import pandas as pd import numpy as np # creating pandas Series object series = pd.Series(np.random.rand(10)) print(series) print("Data type: ", series.dtype )ExplanationIn this example, we have initialized a pandas series object using NumPy random module, which will create a series with random values.Let’s ...

Read More

What does the pandas.series.array attribute do?

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 569 Views

The “.array” is one of the pandas series attributes. it will return a pandas ExtensionArray with the values stored in the series. The “.array” is used to get a zero-copy reference to the underlying data.The resultant array is not like a NumPy array it is an ExtensionArray, and it has different array types based on the data present in the series (dtype).Example 1import pandas as pd # create pandas series with numerical values s1 = pd.Series([1, 2, 3, 4]) print(s1) print(s1.array)ExplanationThe “s1” is the pandas series object which is created by using integer values with length 4. ...

Read More

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

Gireesha Devara
Gireesha Devara
Updated on 09-Mar-2022 2K+ Views

The pandas Series align method is used to align two pandas series objects on basics of the same row and/or column configuration, which is done by specifying the parameters like join, axis, etc.Instead of combining the two series of objects, the pandas series align method aligns them in a specific order. This method takes 10 parameters which are “other, join='outer', axis=None, level=None, copy=True, fill_value=None, method=None, limit=None, fill_axis=0, broadcast_axis=None”. Out of these parameters other, join and axis parameters are very important. Based on these parameters the output series object alignment depends.Example 1import pandas as pd s1 = pd.Series([8, 4, 2, 1], ...

Read More

How to check whether a pandas DataFrame is empty?

Gireesha Devara
Gireesha Devara
Updated on 08-Mar-2022 6K+ Views

Use the DataFrame.empty property to check if DataFrame contains the data or not (empty or not). The DataFrame.empty attribute returns a boolean value indicating whether this DataFrame is empty or not.If the DataFrame is empty, it will return True. and it will return False If the DataFrame is not empty.Example 1In the following example, we have initialized a DataFrame with some data and then applied the empty attribute to check if the empty attribute returns False or not.# importing pandas package import pandas as pd # create an empty DataFrame df = pd.DataFrame([['a', 'b', 'c'], ['b', 'c', 'd'], ['d', ...

Read More

What is ndim in pandas DataFrame?

Gireesha Devara
Gireesha Devara
Updated on 08-Mar-2022 3K+ Views

The ndim is an attribute in the pandas DataFrame which is used to get the integer/number representation of dimensions of the given DataFrame object.As we know, the pandas DataFrame is a two-dimensional data structure that is used to store the data in a tabular format. Regardless of the number of rows and columns lengths or type of data the dimensions of the DataFrame do not affect.The output for the ndim property of pandas DataFrame is always 2.Example 1In this following example, we have applied the ndim attribute to the pandas DataFrame object “df”, this DataFrame is created with a single ...

Read More
Showing 91–100 of 173 articles
« Prev 1 8 9 10 11 12 18 Next »
Advertisements