Professional Documents
Culture Documents
Art - Int Lab 08 Solved
Art - Int Lab 08 Solved
Art - Int Lab 08 Solved
Lab # 8
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.
Output:
# import openpyxl module
Import openpyxl
Wb = openpyxl.Workbook()
Sheet = wb.active
C1 = sheet.cell(row = 1, column = 1)
C1.value = “Hello”
C2 = sheet.cell(row= 1 , column = 2)
C2.value = “World”
C3 = sheet[‘A2’]
1
2020-SE-002
Section: A
Artificial Intelligence (SWE-314) SSUET/QR/114
C3.value = “Welcome”
C4 = sheet[‘B2’]
C4.value = “Everyone”
Wb.save(“sample.xlsx”)
Output:
2. Write a python code 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.
Program
Import pandas as pd
Import numpy as np
2
2020-SE-002
Section: A
Artificial Intelligence (SWE-314) SSUET/QR/114
3. Write a python code to read an excel spreadsheet and only print first two columns using
pandas data frame.
Program:
import pandas as pd
import numpy as np
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin',
'Jonas'],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'no', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
df = pd.DataFrame(exam_data , index=labels)
print(df[['name', 'score']])
Output:
3
2020-SE-002
Section: A
Artificial Intelligence (SWE-314) SSUET/QR/114
4. Write a python code to skip the first two rows of excel spreadsheet and print the output using
pandas data frame.
Program:
Import pandas as pd
D = {‘col1’: [1, 2, 3, 4, 7, 11], ‘col2’: [4, 5, 6, 9, 5, 0], ‘col3’: [7, 5, 8, 12, 1,11]}
Df = pd.DataFrame(data=d)
Print(“Original DataFrame”)
Print(df)
Df1 = df.iloc[3:]
Print(df1)
Output:
4
2020-SE-002
Section: A