































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Well done documents for boards
Typology: Summaries
1 / 39
This page cannot be seen from the preview
Don't miss anything!
































Chapter 1 Data Handling using Pandas New syllabus 2022 - 23
Visit : python.mykvs.in for regular updates Visit : python.mykvs.in for regular updates Visit : python.mykvs.in for regular updates Python Library – Pandas 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.
Basic Features of Pandas
Visit : python.myks.in for regular updates Pandas – Installation/Environment Setup Pandas module doesn't come bundled with Standard Python. If we install Anaconda Python package Pandas will be installed by default. Steps for Anaconda installation & Use
Pandas – Installation/Environment Setup 4.Now move to script folder of python distribution in command prompt (through cmd command of windows).
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.
Data Structures in Pandas Two important data structures of pandas are–Series, DataFrame
Pandas Series It is like one-dimensional array capable of holding data of any type (integer, string, float, python objects, etc.). Series can be created using constructor. Syntax :- pandas.Series( data, index, dtype, copy) Creation of Series is also possible from – ndarray, dictionary, scalar value. Series can be created using
Pandas Series Create an Empty Series e.g. import pandas as pseries s = pseries.Series() print(s) Output Series([], dtype: float64)
Pandas Series Create a Series from dict Eg.1(without index) import pandas as pd import numpy as np data = {'a' : 0., 'b' : 1., 'c' : 2.} s = pd1.Series(data) print(s) Output a 0. b 1. c 2. dtype: float Eg.2 (with index) import pandas as pd import numpy as np data = {'a' : 0., 'b' : 1., 'c' : 2.} s = pd1.Series(data,index=['b','c','d','a']) print(s) Output b 1. c 2. d NaN a 0. dtype: float
Create a Series from Scalar e.g import pandas as pd import numpy as np s = pd1.Series(5, index=[0, 1, 2, 3]) print(s) Output 0 5 1 5 2 5 3 5 dtype: int Note :- here 5 is repeated for 4 times (as per no of index)
Pandas Series Head function e.g import pandas as pd s = pd1.Series([1,2,3,4,5],index = ['a','b','c','d','e']) print (s.head(3)) Output a 1 b. 2 c. 3 dtype: int Return first 3 elements
Pandas Series tail function e.g import pandas as pd s = pd1.Series([1,2,3,4,5],index = ['a','b','c','d','e']) print (s.tail(3)) Output c 3 d. 4 e. 5 dtype: int Return last 3 elements
Pandas Series Retrieve Data Using Label as (Index) e.g. import pandas as pd s = pd1.Series([1,2,3,4,5],index = ['a','b','c','d','e']) print (s[['c','d']]) Output c 3 d 4 dtype: int
Pandas Series Retrieve Data from selection