Found 507 Articles for Pandas

How to access pandas Series elements using the .loc attribute?

Gireesha Devara
Updated on 09-Mar-2022 06:00:04

489 Views

The “.loc” is an attribute of the pandas.Series object which is used to access elements from series based on label indexing. And It works similar to pandas.Series “at” attribute but the difference is, the “at” attribute accesses only a single element whereas the “loc” attribute can access a group of elements using labels.The “loc” attribute accesses the labels based on labels and it also supports slicing object with labels.Example 1import pandas as pd import numpy as np # creating pandas Series object series = pd.Series({'B':'black', 'W':'white', 'R':'red', 'Bl':'blue', 'G':'green'}) print(series) print("Output: ") print(series.loc['B'])ExplanationIn this following example, we created ... Read More

What does the pandas.series.index attribute do?

Gireesha Devara
Updated on 09-Mar-2022 05:57:52

343 Views

A Series is a pandas data structure that is used to store the labeled data in a single dimension, the labels can be anything like text data, integer values, and time sequence. by using these labels we can access elements of a given series and we can do data manipulations too.In pandas.Series the labels are called indexes, If you want to get index labels separately then we can use pandas.Series “index” attribute.Example 1import pandas as pd # creating a series s = pd.Series([100, 110, 120, 130, 140]) print(s) # Getting index data index = s.index print('Output: ') ... Read More

How to access a group of elements from pandas Series using the .iloc attribute with slicing object?

Gireesha Devara
Updated on 09-Mar-2022 05:54:51

424 Views

The pandas.Series.iloc is used to access a group of elements from pandas series object by providing integer-based location index values.The attribute .iloc is taking integer values for accessing a particular series element. Generally, the position-based index values are represented from 0 to length-1. Beyond this range only we can access the series elements otherwise it will raise an “IndexError”. But for slice indexer, it won’t rise “IndexError” for out-of-bound index value, because it allows out-of-bounds indexing.Example 1import pandas as pd import numpy as np # create a sample series s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, ... Read More

How to access pandas Series elements using the .iloc attribute?

Gireesha Devara
Updated on 09-Mar-2022 05:51:11

276 Views

The pandas.Series.iloc attribute is used to access elements from pandas series object that is based on integer location-based indexing. And It is very similar to pandas.Series “iat” attribute but the difference is, the “iloc” attribute can access a group of elements whereas the “iat” attribute access only a single element.The “.iloc” attribute is used to allows inputs values like an integer value, a list of integer values, and a slicing object with integers, etc.Example 1import pandas as pd import numpy as np # create a pandas series s = pd.Series([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) ... Read More

How to access a single value in pandas Series using the integer position?

Gireesha Devara
Updated on 09-Mar-2022 05:47:53

3K+ Views

The pandas.Series.iat attribute is used to access the single series element by using the position index value and It is very similar to the iloc in pandas instead of accessing a group of elements here we will access a single element.The “iat” attribute takes an integer index value for getting and setting the element in a particular position. Let’s take some examples to access a single series element by using the “.iat” attribute.Example 1import pandas as pd # create a series s = pd.Series([65, 66, 67, 68, 69, 70]) print(s) print('Output: ', s.iat[4])ExplanationIn this following example, we ... Read More

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

Gireesha Devara
Updated on 09-Mar-2022 05:44:32

1K+ 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
Updated on 09-Mar-2022 05:40:48

14K+ 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 axes in the pandas series mean?

Gireesha Devara
Updated on 09-Mar-2022 05:36:15

145 Views

The “axes” is an attribute of the pandas series object, this attribute is used to access the group of index labels in the given Series. It will return a python list of index labels.The axes attribute collects all the index labels and returns a list object with all index labels in it.Example 1import pandas as pd # create a sample series s = pd.Series({'A':123, 'B':458, "C":556, "D": 238}) print(s) print("Output: ") print(s.axes)ExplanationIn the following example, we initialized a Series with some data. Then we called the axes property on the series object.OutputA   123 B   458 ... Read More

How to access a single value in pandas Series using the .at attribute?

Gireesha Devara
Updated on 09-Mar-2022 05:32:23

897 Views

The pandas.Series.at attribute is used to access the single labeled element from a Series object and It is very similar to the loc in pandas. The “at” attribute takes label data to get or set the series value in that particular label position.It will return a single value based on the index label, and it also uploads the data at that particular label position.Example 1import pandas as pd # create a sample series s = pd.Series({'A':12, 'B':78, "C":56}) print(s) print(s.at['A'])ExplanationIn this following example, we have created a series using a python dictionary and the index will be ... Read More

What does the pandas.series.array attribute do?

Gireesha Devara
Updated on 09-Mar-2022 05:23:29

410 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

Advertisements