Example: quiz answers

Data Handling using Pandas -1

Informatics PracticesClass XII ( Asper CBSEB oard)Chapter 1 data Handling using Pandas -1 New syllabus 2020-21 Visit : for regularupdatesVisit : for regularupdatesData Handling usingPandas -1 Visit : for regularupdatesVisit : for regularupdatesPythonLibrary MatplotlibMatplotlibisacomprehensivelibr aryforcreatingstatic,animated, Developpublication quality plotswith just a few lines of code2. Useinteractive figuresthat can zoom, pan, can customize and Take full controlof line styles, font properties, axes as well as export and embedto a number of file formats and interactive environmentsVisit : for regularupdatesData Handling usingPandas -1 Visit : for regularupdatesVisit : for regularupdatesPythonLibrary PandasItisamostfamousPythonpackagefordat ascience, : for regularupdatesBasic Features object help a lot in keeping track of a Pandas dataframe, we can have different data types (float, int, string, datetime, etc) all in one has built in functionality for like easy grouping & easy joins of data , IO capabilities.

5. With pandas, you can use patsy for R-style syntax in doing regressions. 6. Tools for loading data into in-memory data objects from different file formats. 7. Data alignment and integrated handling of missing data. 8. Reshaping and pivoting of data sets. 9. Label-based slicing, indexing and subsetting of large data sets. Data Handling using ...

Tags:

  Data, Reshaping

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Data Handling using Pandas -1

1 Informatics PracticesClass XII ( Asper CBSEB oard)Chapter 1 data Handling using Pandas -1 New syllabus 2020-21 Visit : for regularupdatesVisit : for regularupdatesData Handling usingPandas -1 Visit : for regularupdatesVisit : for regularupdatesPythonLibrary MatplotlibMatplotlibisacomprehensivelibr aryforcreatingstatic,animated, Developpublication quality plotswith just a few lines of code2. Useinteractive figuresthat can zoom, pan, can customize and Take full controlof line styles, font properties, axes as well as export and embedto a number of file formats and interactive environmentsVisit : for regularupdatesData Handling usingPandas -1 Visit : for regularupdatesVisit : for regularupdatesPythonLibrary PandasItisamostfamousPythonpackagefordat ascience, : for regularupdatesBasic Features object help a lot in keeping track of a Pandas dataframe, we can have different data types (float, int, string, datetime, etc) all in one has built in functionality for like easy grouping & easy joins of data , IO capabilities.

2 Easily pull data from a MySQL database directly into a ,youcanusepatsyforR-stylesyntaxin different alignment and integrated Handling of and pivoting of slicing, indexing and subsetting of large data Handling usingPandas -1 Visit : for regularupdatesPandas Installation/EnvironmentSetupPandas module doesn't come bundled with we install Anaconda Python package Pandas will be installed for Anaconda installation & the appropriate download installation check for set path and installation start spyder utility of anaconda from pandasaspdin leftpane( ) no error is show then it shows Pandas default we can create another .py file from new window option of file menu for Handling usingPandas -1 Visit : for regularupdatesPandas Installation/EnvironmentSetupPandasinsta llationcanbedoneinStandardPythondistribu tion, (whichisalreadyinstalled).

3 Soinstallitfirst(googleit). install latest version(any one above ) Handling usingPandas -1 Visit : for regularupdatesPandas move to script folder of python distribution in command prompt (through cmd command ofwindows). following commands in command promptserially.>pip installnumpy>pip installsix>pip installpandasWait after each command forinstallationNow we will be able to use Pandas in standard python import Pandas as pd in python (IDLE) it executed without error(it means Pandas is installed on yoursystem) data Handling usingPandas -1 Visit : for regularupdatesData Structures in PandasTwo important data structures of Pandas are Series, , feature of seriesare Homogeneousdata SizeImmutable Values of data MutableData Handling usingPandas -1 Visit : for DataFrameislike feature of DataFrameare Heterogeneousdata SizeMutable Handling usingPandas -1 Visit : for regular updatesPandasSeriesItislikeone-dimension alarraycapableofholdingdataofanytype(int eger,string,float,pythonobjects,etc.)

4 ( data ,index,dtype,copy)Creation of Series is also possible from ndarray, dictionary, scalar value orconstantData Handling usingPandas -1 Visit : for regularupdatesPandasSeriesCreate an Empty Series Pandas aspseries s = () print(s)OutputSeries([], dtype:float64) data Handling usingPandas -1 Visit : for regularupdatesPandasSeriesCreate a Series fromndarrayWithoutindex Pandas aspd1 import numpy asnp1data = (['a','b','c','d'])s = ( data ) print(s)Output1a2b3c4ddtype:objectNote : default index is starting from 0 With Pandas as p1 import numpy asnp1data = (['a','b','c','d'])s = ( data ,index=[100,101,102,103])print(s)Ou tput100a101b102c103d dtype:objectNote : index is starting from100 data Handling usingPandas -1 Visit : for regularupdatesPandasSeriesCreate a Series (without index) import Pandas aspd1 import numpy asnp1data = {'a' : 0.}

5 , 'b' : 1., 'c' :2.}s = ( data ) print(s)Output (with index) import Pandas aspd1 import numpy asnp1data = {'a' : 0., 'b' : 1., 'c' :2.}s = ( data ,index=['b','c','d','a']) print(s)Output :float64 data Handling usingPandas -1 Visit : for regularupdatesCreate a Series from Scalar Pandas aspd1 import numpy asnp1s = (5, index=[0, 1, 2, 3]) print(s)Output 05152535dtype:int64 Note :-here 5 is repeated for 4 times (as per no ofindex) data Handling usingPandas -1 Visit : for regularupdatesPandasSeriesMathsoperation s withSeries Pandas aspd1s = ([1,2,3])t = ([1,2,4]) u=s+t#additionoperation print(u)u=s*t # multiplicationoperationprint(u)021427dty pe:int640114212dtype:int64outputData Handling usingPandas -1 Visit : for Pandas aspd1s = ([1,2,3,4,5],index = ['a','b','c','d','e']) print( (3))Output :int64 Return first 3elementsData Handling usingPandas -1 Visit.

6 For regularupdatesPandasSeries tail function Pandas aspd1s = ([1,2,3,4,5],index = ['a','b','c','d','e']) print( (3))Output :int64 Return last 3elementsData Handling usingPandas -1 Visit : for regularupdatesAccessing data from Series with indexing and Pandas aspd1s = ([1,2,3,4,5],index = ['a','b','c','d','e']) print (s[0])# for 0 indexpositionprint(s[:3])#forfirst3index valuesprint(s[-3:])# : int64 :int64 data Handling usingPandas -1 Visit : for regularupdatesPandasSeriesRetrieve data using Label as (Index) Pandas aspd1s = ([1,2,3,4,5],index = ['a','b','c','d','e']) print(s[['c','d']])Output c3d4dtype:int64 data Handling usingPandas -1 Visit : for regularupdatesPandasSeriesRetrieve data from selectionThere are three methods for data selection: locgets rows (or columns) with particular labels from the index. ilocgets rows (or columns) at particular positions in the index (so it only takes integers).

7 Ix usually tries to behave like locbut falls back to behaving like ilocif a label is not present in the is deprecated and the use of locand ilocis encouraged insteadData Handling usingPandas -1 Visit : for regularupdatesPandasSeriesRetrieve data from >>> s = ( , index=[49,48,47,46,45, 1, 2, 3, 4, 5])>>> [:3] # slice the first three rows49 NaN48 NaN47 NaN>>> [:3] # slice up to and including label 349 NaN48 NaN47 NaN46 NaN45 NaN1 NaN2 NaN3 NaNData Handling usingPandas -1 >>> [:3] # the integer is in the index so [:3] works like loc49 NaN48 NaN47 NaN46 NaN45 NaN1 NaN2 NaN3 NaNVisit : for regularupdatesPandasDataFrameIt is a two-dimensional data structure, just like anytable(with rows &columns).Basic Features of DataFrame Columns may be of differenttypes Size can bechanged(Mutable) Labeled axes (rows /columns) Arithmetic operations on rows andcolumnsStructureRowsIt can be created ( data , index, columns, dtype,copy) data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrame CreateDataFrameIt can be created withfollowings Lists dict Series Numpyndarrays AnotherDataFrameCreate an Pandas as pd1 df1 = () print(df1)outputEmpty DataFrame Columns: [] Index: [] data Handling usingPandas -1 Visit.

8 For regularupdatesPandasDataFrameCreate a DataFrame Pandas as pd1 data1 =[1,2,3,4,5]df1 = (data1)print (df1) Pandas aspd1data1 =[['Freya',10],['Mohak',12],['Dwivedi',1 3]]df1 = (data1,columns=['Name','Age'])print(df1) Write below for numeric value asfloatdf1 = ( data ,columns=['Name','Age'],dtype=float )output00112233445outputNameAge2 Dwivedi1 Freya102 Mohak1213 data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameCreate a DataFrame from Dict of ndarrays Pandas aspd1data1 = {'Name':['Freya','Mohak'],'Age':[9,10]}d f1 = (data1) print(df1)OutputNameAge1 Freya92 Mohak10 Write below as 3rd statement in above prog forindexingdf1 = (data1,index=['rank1','rank2','rank3','r ank4']) data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameCreate a DataFrame from List Pandas aspd1data1 = [{'x': 1, 'y': 2},{'x': 5, 'y': 4, 'z':5}]df1 = (data1) print(df1) below as 3rd stmnt in above program forindexingdf = ( data , index=['first','second']) data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameCreate a DataFrame from Dict Pandas aspd1d1 = {'one' : ([1, 2, 3], index=['a', 'b','c']),'two' : ([1, 2, 3, 4], index=['a', 'b', 'c','d'])}df1 = (d1) print(df1)Outputonetwo Selection -> print (df['one'])Adding a new column by passing as Series: -> df1['three']= ([10,20,30],index=['a','b','c']) Adding a new column using the existing columnsvalues df1['four']=df1['one']+df1['three'] data Handling usingPandas -1 Visit : for regularupdatesCreate a DataFrame from.

9 Txt fileHaving a text file './ ' as:1 1 2 3 1 is shipped with built-in reader methods. For example the seems to be a good way to read (also in chunks) a tabular data pandasdf= ('./ ', delim_whitespace=True, names=('A', 'B', 'C'))will create a DataFrameobjects with column named A made of data of type int64, B of int64 and C of float64 data Handling usingPandas -1 Visit : for regularupdatesCreate a DataFrame from csv(comma separated value) file / import data from cvsfile file contains following dataDate,"price","factor_1","factor_2"20 12-06-11, , , , , , Pandas as pd# Read data from file ' ' # (in the same directory that your python program is based)# Control delimiters, rows, column names with read_csvdata = (" ") # Preview the first 1 line of the loaded data (1) data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameColumn additiondf= ({"A": [1, 2, 3], "B".)}

10 [4, 5, 6]})c = [7,8,9]df[ C'] = cColumnDeletiondel df1['one'] # Deleting the first column using ('two') #Deleting another column using POPfunctionRename columnsdf = ({"A": [1, 2, 3], "B": [4, 5, 6]})>>> (columns={"A": "a", "B": "c"})a c0 1 41 2 52 3 6 data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameData Handling usingPandas -1 Row Selection, Addition, andDeletion#Selection byLabelimport Pandas aspd1d1 = {'one' : ([1, 2, 3], index=['a', 'b','c']),'two' : ([1, 2, 3, 4], index=['a', 'b', 'c','d'])} df1 = (d1)print( ['b'])Output : b, dtype:float64 Visit : for regularupdatesPandasDataFrame#Selection by integerlocation import Pandas aspd1d1 = {'one' : ([1, 2, 3], index=['a', 'b','c']),'two' : ([1, 2, 3, 4], index=['a', 'b', 'c','d'])} df1 = (d1)print( [2])Output : c, dtype:float64 Slice Rows : Multiple rows can be selected using : (df1[2:4]) data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameAddition ofRowsimport Pandas aspd1df1 = ([[1, 2], [3, 4]], columns =['a','b'])df2 = ([[5, 6], [7, 8]], columns =['a','b'])df1 = (df2)print(df1)Deletion ofRows# Drop rows with label0 df1 = (0) data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameIterate over rows in Pandas aspd1 import numpy asnp1raw_data1 = {'name': ['freya','mohak'],'age': [10,1],'favorite_color': ['pink','blue'], 'grade': [88,92]}df1 = (raw_data1, columns = ['name', 'age', 'favorite_color','grade'])for index, row in (): print (row["name"],row["age"])Output freya10mohak1 data Handling usingPandas -1 Visit : for regularupdatesPandasDataFrameHead & Tailhead()returnsthefirstnrows(observeth eindexvalues).


Related search queries