0% found this document useful (0 votes)
16 views15 pages

Python Pandas Part-2

The document explains how to create and manipulate Series objects in Python, including specifying indexes and values. It details various attributes and methods for accessing and modifying Series, such as extracting index and values, counting non-NaN values, and using indexing and slicing for element access. Additionally, it covers setting names and displaying properties like data type, size, and whether the Series is empty.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views15 pages

Python Pandas Part-2

The document explains how to create and manipulate Series objects in Python, including specifying indexes and values. It details various attributes and methods for accessing and modifying Series, such as extracting index and values, counting non-NaN values, and using indexing and slicing for element access. Additionally, it covers setting names and displaying properties like data type, size, and whether the Series is empty.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Specify index(es) as well as data with Series()

➢ While creating Series types object is that along with values, you
also provide indexes.
➢ Both values and indexes are sequences.
➢ Both data and index have to be sequences, None is taken by
default, if you skip these parameters.
Creating a Series object that stores a mix of
different type values:
Series Object Attributes

Attribu Syntax Description Example


te
>>[Link]
Output:-
Extract index of Index(['a', 'b', 'c', 'd'], dtype='object')
Index [Link] In [ ]:
Series

[Link]
Extract values from Output:-
Values [Link] array([10, 20, 30, 40], dtype=int64)
Series

Index
[Link]= “Name” Set index name
name
Attribute Syntax Description Example

Series <SeriesObj>.name=“Name” Set Name of Series


Name

DataType [Link] Display DataType of


Series

Itemsize [Link] Display size of each [Link]


item in bytes

Shape [Link] Display containing


elements
Attribute Syntax Description Example

Size a) [Link] a) Display Dimension


a) Ndim b) [Link] b) Display number of elements
b) Size c) [Link] c) Display total number of bytes
c) nbytes (its equal to size * itemsize)

Empty [Link] Display the Series is empty or not

Index [Link]=[“New To altered the index with new


index number or index
label”]
Method Description Example

Head(n) Return the first n members


of Series. If the value for n
is not passed then by
default n takes first five
series members are
displayed.

Count() Display the number of non-


NaN values given in the
series.
Method Description Example

tail(n) Return the last n


members of Series. If
the value for n is not
passed then by default
n takes last five series
members are displayed.
Accessing Elements of a Series

There are two common ways for accessing the


elements of a series:

➢ Indexing
➢ Slicing

Indexing
✓Indexing in Series is similar to that for NumPy arrays, and is
used to access elements in a series.
✓Indexes are of two types: positional index and labelled index.
✓Positional index takes an integer value that corresponds to its
position in the series starting from 0, whereas labelled index
45
takes any user-defined label as index.
Positional index for accessing a value from a Series.
Slicing
❖Sometimes, we may need to extract a part of a series.

❖This can be done through slicing. This is similar to slicing used


with NumPy arrays.

❖We can determine which part of the series is to be sliced by


specifying the start and end parameters [start : end] with the
series name.

❖When we use positional indices for slicing, the value at the end
index position is excluded, i.e., only (end - start) number of data
values of the series are extracted. 49
50

You might also like