0% found this document useful (0 votes)
17 views4 pages

Load

This document demonstrates how to read an Excel file into a DataFrame and extract various types of information from it. It shows how to get column headings, row counts, slice data, get average values and more.

Uploaded by

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

Load

This document demonstrates how to read an Excel file into a DataFrame and extract various types of information from it. It shows how to get column headings, row counts, slice data, get average values and more.

Uploaded by

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

Ex.No.

3a Load
Aim

To read Excel/CSV/Text files and extract the relevant information

Description

1.Read and display the excel file data

2.Through DataFrame get the details of column headings

3.Through DataFrame get the details of the shape of Excel table

4.Through DataFrame get the particular column values

5.Through DataFrame extract/slice the Excel table values

6.Through DataFrame get the particular row values

7. Through DataFrame make an average of particular column values

PROGRAM

import pandas as pd

d =pd.read_excel("D:\sample.xlsx")

#Get the table data

print("Get the table data:\n")

print(d)

#print(d.to_string())

df=pd.DataFrame(d)

#print(df)

#Get the column heading

print("\nGet the column heading\n",df.columns)

#Get the shape- (no.of rows,no,of columns)

print("\nGet the shape-(no.of rows,no.of columns)\n",df.shape)

#Get particular column values

print("\nGet particular column values\n",df['ROLL NO'])


#Extract/slice the table values- [including this row, excluding this row]

print("\nExtract/slice the table values-[including this row, excluding this row]\n",df[2:5])

#Get the particular row values- through row number identification

print("\nGet the particular row values-through row number identification\n",df.loc[7])

#Get the particular row values- through 'Roll number' identification

print("\nGet the particular row values-through 'Roll number' identification\n",d.loc[d['ROLL


NO']==105])

#Make an average of total marks

df=d['TOTAL']/5

print("\nMake an average of total marks:\n",df)

OUTPUT:

Get the table data:

Unnamed: 0.1 Unnamed: 0 ROLL NO NAME ... MATHS SCIENCE SOCIAL TOTAL

0 0 0 101 DEEPA ... 50 67 50 284

1 1 1 102 DINESH ... 56 89 56 346

2 2 2 103 KAVIYA ... 80 80 80 400

3 3 3 104 RACHEAL ... 89 87 89 441

4 4 4 105 RAJAN ... 90 98 90 466

5 5 5 106 RAMYA ... 67 76 67 353

6 6 6 107 ROHAN ... 56 67 56 302

7 7 7 108 ROHINI ... 57 65 57 301

8 8 8 109 SANDHYA ... 58 56 58 286

9 9 9 110 SARANYA ... 49 45 49 237

[10 rows x 10 columns]


Get the column heading

Index(['Unnamed: 0.1', 'Unnamed: 0', 'ROLL NO', 'NAME', 'ENGLISH', 'TAMIL',

'MATHS', 'SCIENCE', 'SOCIAL', 'TOTAL'],

dtype='object')

Get the shape-(no.of rows,no.of columns)

(10, 10)

Get particular column values

0 101

1 102

2 103

3 104

4 105

5 106

6 107

7 108

8 109

9 110

Name: ROLL NO, dtype: int64

Extract/slice the table values-[including this row, excluding this row]

Unnamed: 0.1 Unnamed: 0 ROLL NO NAME ... MATHS SCIENCE SOCIAL TOTAL

2 2 2 103 KAVIYA ... 80 80 80 400

3 3 3 104 RACHEAL ... 89 87 89 441

4 4 4 105 RAJAN ... 90 98 90 466

[3 rows x 10 columns]

Get the particular row values-through row number identification

Unnamed: 0.1 7

Unnamed: 0 7
ROLL NO 108

NAME ROHINI

ENGLISH 57

TAMIL 65

MATHS 57

SCIENCE 65

SOCIAL 57

TOTAL 301

Name: 7, dtype: object

Get the particular row values-through 'Roll number' identification

Unnamed: 0.1 Unnamed: 0 ROLL NO NAME ... MATHS SCIENCE SOCIAL TOTAL

4 4 4 105 RAJAN ... 90 98 90 466

[1 rows x 10 columns]

Make an average of total marks:

0 56.8

1 69.2

2 80.0

3 88.2

4 93.2

5 70.6

6 60.4

7 60.2

8 57.2

9 47.4

Name: TOTAL, dtype: float64

You might also like