Contents

  1. Python Setup and Installation
  2. Introduction to Python Libraries and its Overview
  3. PyCharm IDE Installation
  4. Series and its creation in different ways
  5. Indexing in Series or Accessing Series Elements
  6. Slicing in Series or Subset Accessing in Series
  7. Series Attributes and functionalites
  8. Concept of np.NaN and more about indexing
  9. Head and Tail Functions in Series
  10. Mathematical Functions in Series Objects
  11. DataFrame in Python Pandas and its creation in different ways
  12. DataFrame from CSV and Text File
  13. DataFrame Attributes and other functionalites
  14. Iloc Methods for subset accessing in DataFrame
  15. Loc Methods for subset accessing in DataFrame
  16. Adding Columns to DataFrame
  17. Adding Rows to DataFrame
  18. Deleting Columns from DataFrame
  19. Deleting Rows from DataFrame
  20. Renaming Row and Column Labels in DataFrame

Series & its creation in different ways

Series is one of the Data Structure of Python Pandas which stores data in Linear fashion. Series is


Note: While creating series, the "S" of Series must be capital..

Eg. Series of int for storing marks of a subject or series of float for storing percentage of students, etc.

Creating Series from Numpy Arrays:

While creating series from numpy arrays, we firstly create a numpy array and then we pass the created numpy array from Series funcion. If you guys are not familiar with arrays, so first you must be knowing what it actually is.
Arrays are datatypes which stores similar type of data i.e. either int or float or string/object in contiguous memory locations.

#importing required libraries

import pandas as pd
import numpy as np

#creating a numpy array of names
arr = np.array(['Aman', 'Raghav', 'Shubham', 'Rohit', 'Yash'])
ser = pd.Series(arr)

#printing the created series below
print(ser)

OUTPUT:

0 Aman
1 Raghav
2 Shubham
3 Rohit
4 Yash
dtype: object

Creating Series from Lists:

Lists are basically the collections of items which can be either of same datatype or different or both simultaneouly. List elements are enclosed by [] and are seperated by commas.
Eg. kirana = ['Sugar', 'Rice','Tea','Cashew',100,68.8]

#importing required libraries

import pandas as pd

#creating a list of kirana items😂🤣
kirana = ['Sugar','Rice','Tea','Oil','Cookies']
ser = pd.Series(kirana)

#printing the created series below
print(ser)

OUTPUT:

0 Sugar
1 Rice
2 Tea
3 Oil
4 Cookies
dtype: object

Creation of Series from Dictionary:

Dictionary is also a datatype of Python which stores data in the form of key and value pair. Every value that is element is associated with its corresponding key which can be used to access the value. In a dictionary, every pair is seperated with commas(,) and every key and its value is seperated by colon(:).

Example:
dict = key1:value1, key2:value2, key3:value3, ------
days = {1:'Sunday', 2:'Monday', 3:'Tuesday', 4:'Wednesday', 5:'Thursday', 6:'Friday', 7:'Saturday'}

Note:When we create series from dictionary, key becomes the index of the series and value becomes the data of the Series.

#importing required libraries

import pandas as pd

#creating a dictionary of days of week
days = {'Day1':'Sunday', 'Day2':'Monday', 'Day3':'Tuesday', 'Day4':'Wednesday', 'Day5':'Thursday', 'Day6':'Friday', 'Day7':'Saturday'}

ser = pd.Series(days)

#printing the created series below
print(ser)

OUTPUT:

Day1 Sunday
Day2 Monday
Day3 Tuesday
Day4 Wednesday
Day5 Thursday
Day6 Friday
Day7 Saturday
dtype: object

Creating Series from Scalar Value:

If we want to create the series such that all the data values are to be same so, we can use the method of scalar value. For this, we use a range function which gives the number of values in the resultant series.

#importing required libraries

import pandas as pd

#creating a series of scalar value
ser = pd.Series("Welcome to IPHM",range(0,5))

#printing the created series below
print(ser)

OUTPUT:

0 Welcome to IPHM
1 Welcome to IPHM
2 Welcome to IPHM
3 Welcome to IPHM
4 Welcome to IPHM
5 Welcome to IPHM
dtype: object
Download Notes