0% found this document useful (0 votes)
39 views17 pages

Class X11 Dataframe Notes PDF

Class

Uploaded by

prakhar200737
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views17 pages

Class X11 Dataframe Notes PDF

Class

Uploaded by

prakhar200737
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

DPS AJMER

CLASS- XII NOTES


INFORMATICS PRACTICES (065)
TOPIC- DATAFRAME

DATAFRAME-It is a two-dimensional object that is useful in


representing data in the form of rows and columns. It is similar to a
spreadsheet or an SQL table. This is the most commonly used pandas
object. Once we store the data into the Dataframe, we can perform
various operations that are useful in analyzing and understanding the
data.

PROPERTIES OF DATAFRAME
A Dataframe has axes (indices)-
➢ Row index (axis=0)
➢ Column index (axes=1)
2. It is similar to a spreadsheet , whose row index is called index and
column index is called column name.
3. A Dataframe contains Heterogeneous data.
4. A Dataframe Size is Mutable.
5. A Dataframe Data is Mutable.
A data frame can be created using any of the following
1. Serie
2. Lists
3. Dictionary
4. A numpy 2D array

How to create Dataframe From Series


DataFrame from Dictionary of Series

DataFrame from List of Dictionaries


Select operation in data frame
To access the column data ,we can mention the column name as
subscript.
e.g. - df[empid] This can also be done by using df.empid. To access
multiple columns we can write as df[ [col1, col2,---] ] Example –

>>df.empid or df[‘empid’]
0 101
1 102
2 103
3 104
4 105
5 106
Name: empid, dtype: int64
>>df[[‘empid’,’ename’]]
empid ename
0 101 Sachin
1 102 Vinod
2 103 Lakhbir
3 104 Anil
4 105 Devinder
5 106 UmaSelvi

To Add & Rename a column in data frame

To Delete a Column in data frame


We can delete the column from a data frame by using any of the the
following –
To Delete a Column Using drop()
Accessing the data frame through loc() and iloc() method or
indexing using Labels
Pandas provide loc() and iloc() methods to access the subset from a
data frame using row/column.
Accessing the data frame through loc()
It is used to access a group of rows and columns.
Syntax
Accessing the data frame through iloc()
It is used to access a group of rows and columns based on numeric
index value. Syntax
Df.loc[StartRowindexs : EndRowindex, StartColumnindex :
EndColumnindex]
Note -If we pass : in row or column part then pandas provide the
entire rows or columns respectively.
HEAD() AND TAIL() METHOD
The method head() gives the first 5 rows and the method tail()
returns the last 5 rows
To display first 2 rows we can use head(2) and to returns last2 rows
we can use tail(2) and to return 3rd to 4th row we can write df[2:5].
Boolean Indexing in Data Frame
Boolean indexing helps us to select the data from the DataFrames
using a boolean vector. We create a DataFrame with a boolean index
to use the boolean indexing.
CSV File
A CSV is a comma separated values file, which allows data to be
saved in a tabular format. CSV is a simple file such as a spreadsheet
or database. Files in the csv format can be imported and exported
from programs that store data in tables, such as Microsoft excel or
Open Office.
CSV files data fields are most often separated, or delimited by a
comma. Here the data in each row are delimited by comma and
individual rows are separated by newline.
To create a csv file, first choose your favorite text editor such as-
Notepad and open a new file. Then enter the text data you want the
file to contain, separating each value with a comma and each row
with a new line. Save the file with the extension.csv. You can open
the file using MS Excel or another spread sheet program. It will create
the table of similar data.
Exporting data from dataframe to CSV File
To export a data frame into a csv file first of all, we create a data
frame say df1 and use dataframe.to_csv(‘ E:\Dataframe1.csv ’ )
method to export data frame df1 into csv file Dataframe1.csv.

You might also like