Docsity

Series (pandas)....., Slides of Computer science

Toggle sidebar
bg1
Unit No
Unit Name
Marks
1
Data Handling using Pandas and Data
Visualization
30
2
Database Query using SQL
25
3
Introduction to Computer Networks
7
4
Societal Impacts
8
Practical
30
Total
100
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download Series (pandas)..... and more Slides Computer science in PDF only on Docsity!

Unit No Unit Name Marks

1 Data Handling using Pandas and Data Visualization

30

2 Database Query using SQL^25

3 Introduction to Computer Networks^7

4 Societal Impacts^8

Practical (^30)

Total (^100)

Unit 1 : Data Handling

using Pandas and Data

Visualization

Chapter 1 : Python Pandas - 1

By,

Sunil Tank

PGT (CS/IP)

Pandas : Pan el Da ta System by Wes McKinney

  • Python Library used for data Analysis.*

Q. Write Definition of Data Frame

Pandas is the most popular open source python library used for data analysis

It is a most famous Python package for data science, which offers powerful and flexible data structures that make data analysis and manipulation easy. Pandas makes data importing and data analyzing much easier. Pandas builds on packages like NumPy and matplotlib to give us a single & convenient place for data analysis and visualization work.

  • It is a package useful for data analysis and manipulation.
  • Pandas provide an easy way to create, manipulate and wrangle the data.
  • Pandas provide powerful and easy-to-use data structures, as well as the means to quickly perform operations on these structures.

Installation of pandas:

Pandas installation can be done in Standard Python distribution, using following steps. 1.There must be service pack installed on our computer if we are using windows. If it is not installed then we will not be able to install pandas in existing Standard Python(which is already installed). So install it first(google it).

  1. We can check it through properties option of my computer icon.
  2. Now install latest version(any one above 3.4) of python.
  3. Now move to script folder of python distribution in command prompt (through cmd command of windows). 5.Execute following commands in command prompt serially. >pip install numpy >pip install six >pip install pandas Wait after each command for installation Now we will be able to use pandas in standard python distribution. 6.Type import pandas as pd in python (IDLE) shell. 7.If it executed without error(it means pandas is installed on your system)

Q. Write command to install pandas in standard python distribution. pip install pandas

Series

Series is a one-dimensional array like structure with homogeneous data, which can be used to handle and manipulate data.

Q. Why Series, Why not Array?

What makes it special is its index attribute, which has incredible functionality and is heavily mutable.

It has two parts-

**1. Data part (An array of actual data)

  1. Associated index with data (associated array of indexes or data labels)**

Index Data 0 10 1 15 2 18 3 22

Key Points :

● Homogeneous data ● Size Immutable ● Values of Data Mutable

  1. We can say that Series is a labeled one-dimensional array which can hold any type of data.
  2. Data of Series is always mutable , means it can be changed.
  3. But the size of Data of Series is always immutable , means it cannot be changed. 4. Series may be considered as a Data Structure with two arrays out which one array works as Index (Labels) and the second array works as original Data. 5. Row Labels in Series are called Index. Syntax to create a Series: =pandas.Series (data, index=idx (optional))

= pandas.Series(data, index = idx, [dtype = ])

The data supplied to Series() can be either:

● A Sequence (list)

● An ndarray

● A scalar value

● A python dictionary

● A mathematical expression/function

  1. Non empty Series using Sequence : Pass any sequence of value as data argument to Series() Function.

Program using range() Output

Program using list (^) Output

Program using Tuple Output

Program using characters and string Output

Series.index = [ ‘first’, ‘second’, ‘third’, ‘fourth’, ‘fifth’]

2. Specify data as NumPy Array :

Using arange() function of NumPy

import pandas as pd

import numpy as np

print(pd.Series(np.arange(5,10,.5)))

4. Series Creation using Scalar value :

  • The Scalar value (given as data) will be repeated to match the length of Index.
  • The data you provide it can be single value or else can be scalar value.
  • If it is Scalar value then index argument must be provided to the Series() function.
  • Eg : ser = pd.Series(data = 10, index=range(0,4))
    • ser = pd.Series (‘Sunil’, index = range(10,20))

Series Additional Functionality

1. Specify data with NaN value : if the data element is not available you can specify NaN in place of data element. 2. Specify index and data parameter in Series( ) : import pandas as pd sr = pd. Series(data = *10,20,30,40+, index = *‘A’, ‘B’,’C’,’D’+) print(sr)

What is the Data type of NaN?

Attributes of Series( ) Function :

If we need to check the information of Any Series( ) Object then we need to use its Attributes. The Series attribute is defined as any information related to the Series object such as size, data type. etc. Below are some of the attributes that you can use to get the information about the Series object:

syntax: .

Attribute Description Series.index Returns index of the series Series.values Returns ndarray Series.dtype Returns dtype object of the underlying data Series.shape Returns tuple of the shape of underlying data Series.nbytes Returns number of bytes of underlying data Series.ndim Returns the number of dimension Series.size Returns the number of elements Series.itemsize Returns the size of the dtype Series.hasnans Returns true if there are any NaN Series.empty Returns true if series object is empty