Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Artificial Intelligence (SWE-314) SSUET/QR/114

Lab # 8
Dataset Preparation with Excel spreadsheet

OBJECTIVE
Dataset preparation by selecting all the possible features on the given scenario using excel. Load
designated data set to working environment.

Lab Tasks:

1. Write a python code to load an excel spreadsheet containing two different sheets and print
both of them.

source code
import pandas as pd
data =pd.read_excel('Book.xlsx',sheet_name=None)
print(data)
Output

2. Write a python cade to generate a pandas data frame having 4 columns and 5 rows. Column 1
must contain the index values like Ali, Amir, Kamran, etc and Row 1 must contain the
subject names.
Artificial Intelligence (SWE-314) SSUET/QR/114

source code
import pandas as pd
cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
'Price': [32000,35000,37000,45000] }
df = pd.DataFrame(cars, columns = ['Brand', 'Price'])
df.to_excel ('xport_dataframe.xlsx', index = False, header=True)
Output

3. Write a python code to read an excel spreadsheet and only print first two columns using
pandas data frame.
source code
import pandas as pd
data =pd.read_excel('Book.xlsx')
#print(data)
colA=data['A'].values.tolist()
colB=data['B'].values.tolist()
print(colA)
print(colB)

Output

4. Write a python code to skip the first two rows of excel spreadsheet and print the output using
pandas data frame.

source code
import pandas as pd
data =pd.read_excel('Book.xlsx')
print("Before")
print(data)
Artificial Intelligence (SWE-314) SSUET/QR/114

print("After")
data =pd.read_excel('Book.xlsx',skiprows=2)
print(data)
#colA=data['A'].values.tolist()
#colB=data['B'].values.tolist()
#print(colA)
#print(colB)

Output

You might also like