Python for Data Science: Chapter 5: NumPy and Pandas Libraries

Pandas: Exploring Data using Series

Python library

The Pandas series is like a column in a table. It is basically a one dimensional array holding data of any type.

Data Structures

• In Pandas, there are two important data structures that are used –

1) Series and

2) Data frames.

Let us discuss them in detail


Exploring Data using Series

• The Pandas series is like a column in a table. It is basically a one dimensional array holding data of any type.

Using the pd.Series function the series can be created. For example ‒

In [3]: import pandas as pd

a = [2,4,6,8,10]

x = pd.series(a)

print(x)

0     2

1     4

2      6

3      8

4      10

dtype: int64

Note that the values of the series are displayed along with the index number. The index number starts with 0.


Syntax of series

pandas.Series( data, index, dtype, copy)


Parameters:

data(required): This is the input data, which can be any list, dictionary, etc.

index(Optional) : The index for the value you use for the series is represented by this number.

dtype(Optional): This describes the values contained in the series.

• copy(Optional): This makes a copy of the input data.


Creating labels

We can create labels to the elements of the series instead of index numbers. For example

In [4]: import pandas as pd

a = [2,4,6,8,10]

x = pd.series(a,index = ["a","b","c","d","e"])

print(x)

a    2

b    4

c     6

d     8

e    10

dtype: int64


Accessing specific element of series

We can access particular element of the series as follows ‒

In [7]: print(x[3])

8

or

In [6]: print(x["d"])

8


Change in data type of the elements

We can change the data type of the series elements. It can be done as follows ‒

In [8]: import pandas as pd

a = [2,4,6,8,10]

x = pd.Series(a,index = ["a","b","c","d","e"], dtype=float)

print(x)

a     2.0

b     4.0

c     6.0

d     8.0

e     10.0

dtype: float64

 

Python for Data Science: Chapter 5: NumPy and Pandas Libraries : Tag: Computer Programming, Python, Data Science : Python library - Pandas: Exploring Data using Series


Python for Data Science: Chapter 5: NumPy and Pandas Libraries



Under Subject


Python for Data Science

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation



Related Subjects


English Essentials II

EN25C02 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation



Linear Algebra

MA25C02 2nd Semester | 2025 Regulation


Applied Physics (CSIE) II

PH25C03 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Digital Principles and Computer Organization

CS25C06 2nd Semester AIDS, CSE, IT, CSE(CY) Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electrical and Electronics Engineering

EE25C01 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Python for Data Science

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation


Re-Engineering for Innovation

ME25C05 2nd Semester | 2025 Regulation | 2nd Semester 2025 Regulation


Python for Data Science - Laboratory

AD25201 2nd Semester AIDS Dept | 2025 Regulation | 2nd Semester 2025 Regulation