You are on page 1of 34

TECHNO INDIA GROUP PUBLIC SCHOOL

SILIGURI
AFFILIATION CODE: 2430126

ALL INDIA SENIOR SCHOOL CERTIFICATE


EXAMINATON
SESSION: 2022-23

PHYSICS ACTIVITY (Sub. Code: 042)

NAME:
ROLL NO:
STD: XII STREAM: SCIENCE
INDEX
ASSIGNMENT TOPIC PAGE NO.
NO.
1 Creation of DataFrame; Adding and deleting a Column

2 Creation of DataFrame, iterrows function

3 Creation of Series and set_index command

4 Extracting data by using loc function from a DataFrame

5 Deletion of column from a DataFrame using drop

6 Program to create a DataFrame and display names and other


information those who have scored more than 25.

7 Program to find the differences of ages where first age is


greater than the second age

8 Program to create a csv file in MS-Excel and extract data


from it from Python Interface

9 Program to create a csv file in MS-Excel by using a


DataFrame as a Data source.

10 Program to create a csv file in MS-Excel by using a person3.csv


as a Data source. and display all data, total count of rows etc.

11 Program to add a row in an existing DataFrame

12 Program to add a Column Total in an existing DataFrame

13 Program to rename multiple columns in existing


DataFrame
14 Program to remove a column using drop function and
other statistics
15 Program to display the first three rows of an existing
DataFrame
16 Write a program using Matplotlib to draw a bar graph to
display the percentage of usage of Programming Languages
in an institution.
INDEX
ASSIGNMENT TOPIC PAGE NO.
NO.
17 Program to display the percentage of students using bar
graph (Matplotlib)
18 Program using Matplotlib to draw a bar graph to display
the consumption of coffee in a Coffee Shop.
19 Program using Matplotlib to display graphically the
sales of unit of Bathing soaps in a departmental store.
20 MY-SQL Queries
PYTHON ASSIGNMENTS
Assignment 1 Dt: 22.04.22

Language Used: PYTHON Ver 3.10.2 IDE used: Python(x,y)

Write a program to create a DataFrame. Add a column Total into it and delete the column SST.

Structure of the DataFrame

CODING:
#creation of DataFrame and Remove the column SST
import pandas as pd
Student_result={'Candidates':['Kabir','Ridhima','Ankur','Manas','Ranji'],
'Eng':[55,60,35,60,60],'SST':[60,56,45,50,45],
'Math':[40,60,60,80,70],'Comp':[60,69,60,80,80]}
df1=pd.DataFrame(Student_result)
print("DataFrame Created by using Student_Result")
print(df1)
#Addition of column Total
Student_result['Total']=[215,245,200,270,255]
df2=pd.DataFrame(Student_result)
print(df2)
#Deletetion of Column SST
df1.drop(['SST'],axis=1,inplace=True)
print(df1)

OUTPUT:
Assignment 2 Dt: 28.04.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to create a DataFrame and display all its data by using iterrows() function.
#to create a dataframe and add a column and iteration of rows
import pandas as pd
students={'Names':
['Amit','Ajay','Atul','Abhyay','Amay','Bijoy','Bimal','Binay','Darvesh','Durgesh','Ela'],
'Age':[18,19,17,18,19,20,21,20,19,17,20],
'Prev_Perc':[78.0,90.2,87.2,79.3,92.0,91.0,90.0,89.0,92.0,80.0,67.0]
}
df1=pd.DataFrame(students) #Creation of a DataFrame object by passing a dictionary
print(df1)
students['Pr_Prcent']=[45.6,78.9,67.0,88.0,34.0,87.0,90.0,56.5,38.9,89.0,55.9]
df1=pd.DataFrame(students)
print(df1)
df1.drop(['Prev_Perc'],axis=1,inplace=True)
print(df1)
for index, row in df1.iterrows():
#print(index+1,':',row)
print(row['Names'],row['Age'],row['Pr_Prcent'])

Output:
Assignment 3 Dt: 04.05.22

Language Used: PYTHON Ver 3.10.2 IDE used: Python(x,y)

Write a program to create a series using dictionary and index it with respect to any column.
#using set_index column
import pandas as pd
cities = {"name": ["London", "Berlin", "Madrid", "Rome",
"Paris", "Vienna", "Bucharest", "Hamburg",
"Budapest", "Warsaw", "Barcelona",
"Munich", "Milan"],
"population": [8615246, 3562166, 3165235, 2874038,
2273305, 1805681, 1803425, 1760433,
1754000, 1740119, 1602386, 1493900,
1350680],
"country": ["England", "Germany", "Spain", "Italy",
"France", "Austria", "Romania",
"Germany", "Hungary", "Poland", "Spain",
"Germany", "Italy"]}

city_frame = pd.DataFrame(cities)
city_frame2 = city_frame.set_index("country") #new object created
print(city_frame2)

Output:
Assignment 4 Dt: 16.06.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to extract data from a DataFrame using Loc() function.


import pandas as pd

numbers = {'Numbers': [1,2,3,4,5,6,7,8,9,10]}


df = pd.DataFrame(numbers,columns=['Numbers'])

df.loc[df['Numbers'] <= 4, 'Equal or less than 4'] = 'True'


df.loc[df['Numbers'] > 4, 'Greater than 4'] = 'Its True'

print (df)

Output

Assignment 5 Dt: 20.06.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to remove a column from a DataFrame using drop() function.

#Creation of Dataframe deleting a column using drop


import pandas as pd
students={'Name':['Amit','Ajay','Atul','Abhyay','Amay'],
'Age':[18,19,17,18,19],'perc_prev':[78.0,90.2,87.2,79.3,92.0]}
df1=pd.DataFrame(students)

df1['Perc']=[90,87.2,72,69,89]
print(df1)

#Deleting Column
df1.drop(['perc_prev'],axis=1,inplace=True)
print(df1)

Output
Assignment 6 Dt: 01.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to create a DataFrame and display names and other information those who have scored
more than 25.
#Creating a dataframe and displaying the details for those who have scored more than 25
import pandas as pd
d={'Name':['Ajay','Vinay','Sonia','Deep','Radhika','Shaurya','Noni','Bobby',
'Ritu','Anjana','Amit','Rinku'],
'Age':[26,24,23,22,25,24,26,24,22,23,24,24],
'Score':[85,63,55,74,31,77,85,63,42,62,89,86],
'Eng':[67,88,90,32,34,55,68,77,88,54,43,33]
}
score_df=pd.DataFrame(d,columns=['Name','Age','Score','Eng'])
print(score_df[score_df['Age']>25])
print(score_df.min())

Output
Assignment 7 Dt: 04.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to find the difference of ages where first age is greater than the second age.

#Program to find the differences of ages where first age is greater than the second age
import pandas as pd
import numpy as np

d1= {'Age 1': [23,45,21],'Age 2': [10,20,50]}


df = pd.DataFrame(d1, columns = ['Age 1','Age 2'])
print("Original DataFrame")
print(df)
#function to find age difference when first item is greater than sencond one
def agediff (var1,var2,var3):
df[var3]= np.where((df[var1]-df[var2])>0, df[var1]-df[var2], "FALSE")
return df
df1 = agediff('Age 1','Age 2','Diff')#Function call
print("Age Difference")
print (df1)

Output

Assignment 8 Dt: 07.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to create a csv file in MS-Excel and extract data from it from Python Interface.
Name of the file results1.csv
#Writing to a csv file
# importing the csv module
import csv

# field names
fields = ['Name', 'Branch', 'Year', 'CGPA']

# data rows of csv file


rows = [ ['Nikhil', 'COE', '2', '9.0'],
['Sanchit', 'COE', '2', '9.1'],
['Aditya', 'IT', '2', '9.3'],
['Sagar', 'SE', '1', '9.5'],
['Prateek', 'MCE', '3', '7.8'],
['Sahil', 'EP', '2', '9.1']]

# name of csv file


filename = "result1.csv"

# writing to csv file


with open(filename, 'w') as csvfile:
# creating a csv writer object
csvwriter = csv.writer(csvfile)

# writing the fields


csvwriter.writerow(fields)

# writing the data rows


csvwriter.writerows(rows)

Output

Assignment 9 Dt: 12.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to create a csv file in MS-Excel by using a DataFrame as a Data source.

import pandas as pd

# creating a data frame


df = pd.DataFrame([['Jack', 24,'Green'], ['Rose', 22,'Blue'],['Jack',13,'Blue']], columns = ['Name',
'Age','House']) ##DATAFRAME

# writing data frame to a CSV file


df.to_csv('person2.csv')
print(pd.read_csv('person2.csv'))

import csv
with open("person2.csv", 'r') as file:
csv_file = csv.DictReader(file)
for row in csv_file:
print(dict(row))

Output

Assignment 10 Dt: 18.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to create a csv file in MS-Excel by using a person3.csv as a Data source. and display all
data, total count of rows etc.

#reading writing data in csv file


# importing csv module
import csv

# csv file name


filename = "person3.csv"

# initializing the titles and rows list


fields = []
rows = []
# reading csv file
with open(filename, 'r') as csvfile:
# creating a csv reader object
csvreader = csv.reader(csvfile)

# extracting field names through first row


fields = next(csvreader)

# extracting each data row one by one


for row in csvreader:
rows.append(row)

# get total number of rows


print("Total no. of rows: %d"%(csvreader.line_num-1))

# printing the field names


print('Field names are:' + ', '.join(field for field in fields))

# printing first 5 rows


print('\nFirst 5 rows are:\n')
for row in rows[:5]:
# parsing each column of a row
for col in row:
print("%10s"%col),
print('\n')

Output of Assignment 10
Assignment 11 Dt: 20.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to add a row in an existing DataFrame.

#creation of DataFrame and Add a row


import pandas as pd
Student_result={'Candidates':['Kabir','Ridhima','Ankur','Manas','Ranji'],
'Eng':[55,60,35,60,60],'SST':[60,56,45,50,45],
'Math':[40,60,60,80,70],'Comp':[60,69,60,80,80]}
df1=pd.DataFrame(Student_result)
print("DataFrame Created by using Student_Result")
print(df1)
df1=pd.DataFrame([['Sujoy',69,89,64,88]],columns=['Candidates','Eng','SST','Math','Comp'])
print(df1)
Output

Assignment 12 Dt: 25.07.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to add a Column Total in an existing DataFrame.

#creation of DataFrame and add a column


import pandas as pd
Student_result={'Candidates':['Kabir','Ridhima','Ankur','Manas','Ranji'],
'Eng':[55,60,35,60,60],'SST':[60,56,45,50,45],
'Math':[40,60,60,80,70],'Comp':[60,69,60,80,80]}
df1=pd.DataFrame(Student_result)
print("DataFrame Created by using Student_Result")
print(df1)
#Addition of column Total
Student_result['Total']=[215,245,200,270,255]
df2=pd.DataFrame(Student_result)
print(df2)

Output

Assignment 13 Dt: 01.08.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to rename multiple columns in an existing DataFrame.

#Renaming Multiple Columns


import pandas as pd

data = {'Colors': ['Triangle', 'Square', 'Circle'],


'Shapes': ['Red', 'Blue', 'Green']
}

df = pd.DataFrame(data,columns = ['Colors','Shapes'])
print(df)

df = df.rename(columns = {'Colors':'Shapes','Shapes':'Colors'})

print (df)
Output

Assignment 14 Dt: 05.08.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to remove a column in an existing DataFrame and to describe other details of the
DataFrame.

#Program to remove a column using drop function and other statistics


import pandas as pd

mydata = {'names': ['Somu', 'Kiku', 'Amol', 'Lini'],


'physics': [68, 74, 77, 78],
'chemistry': [84, 56, 73, 69],
'algebra': [78, 88, 82, 87]}

#create dataframe
df_marks = pd.DataFrame(mydata)
print('Original DataFrame\n--------------')
print(df_marks)
#delete column
df_marks.drop(['chemistry'],axis=1,inplace=True)
print('\n\nDataFrame after deleting column Chemistry\n--------------')
print(df_marks)
print(df_marks.describe())

Output

Assignment 15 Dt: 10.08.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program to display the first three rows of an existing DataFrame.

#Program using head function


import pandas as pd
import numpy as np

#Create a Dictionary of series


d = {'Name':pd.Series(['Tom','James','Ricky','Vin','Steve','Smith','Jack','Shiva']),
'Age':pd.Series([25,26,25,23,30,29,23,34]),
'Rating':pd.Series([4.23,3.24,3.98,2.56,3.20,4.6,3.8,4.7])}

#Create a DataFrame
df = pd.DataFrame(d)
print ("Our data frame is:")
print df
print ("The first three rows of the data frame is:")
print df.head(3)

Output

Assignment 16 Dt: 17.08.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program using Matplotlib to draw a bar graph to display the percentage of usage of
Programming Languages in an institution.

import numpy as np
import matplotlib.pyplot as plt
lbl=('Python','C++','Java','Perl','Scala','Lisp')
y=np.arange(len(lbl))#counting how many objects
per=[10,8,6,4,2,1]

plt.bar(y,per,align='center',color='r')
plt.xticks(y,lbl)
plt.ylabel('Usage')
plt.title('Programming Language Usage')
plt.show()
Output:

Assignment 17 Dt: 25.08.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program using Matplotlib to draw a bar graph to display the percentage of students in annual
examination in an institution.

import matplotlib.pyplot as plt


import numpy as np
label = ['Anil', 'Vikas', 'Dharma','Mahen', 'Manish', 'Rajesh']
per = [94,85,45,25,50,54]
index = np.arange(len(label))
plt.bar(index, per,color='orange')
plt.xlabel('Student Name', fontsize=10)
plt.ylabel('Percentage', fontsize=10)
plt.xticks(index, label, fontsize=9,rotation=30)
plt.title('Percentage of Marks achieved by student Class XII')
plt.show()

Output
Assignment 18 Dt: 01.09.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program using Matplotlib to draw a bar graph to display the consumption of coffee in a Coffee
Shop.

import matplotlib.pyplot as plt


import numpy as np
import matplotlib.pyplot as plt
# restore default parameters:
plt.rcdefaults()
fig, ax = plt.subplots()
personen = ('Ayush', 'Ishan', 'Manali', 'Surya', 'Tulip')
y_pos = np.arange(len(personen))
cups = (15, 22, 24, 39, 12)
ax.barh(y_pos, cups, align='center',
color='green', ecolor='black')
ax.set_yticks(y_pos)
ax.set_yticklabels(personen)
ax.invert_yaxis()
ax.set_xlabel('Cups')
ax.set_title('Coffee Consumption')
plt.show()

Output

Assignment 19 Dt: 10.09.22

Language Used: PYTHON Ver 3.10.2 IDE used: IDLE

Write a program using Matplotlib to display graphically the sales of unit of Bathing soaps in a
departmental store. Data have been taken here from csv file name company—sales—data.csv

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv("company_sales_data.csv")
monthList = df ['month_number'].tolist()
bathingsoapSalesData = df ['bathingsoap'].tolist()
plt.bar(monthList, bathingsoapSalesData)
plt.xlabel('Month Number')
plt.ylabel('Sales units in number')
plt.title(' Sales data')
plt.xticks(monthList)
plt.grid(True, linewidth= 1, linestyle="--")
plt.title('Bathing Soap Sales Data')
plt.savefig("bathing.png", dpi=150) #Image has beensaved
plt.show()
Output

MY SQL QUERY
SQL Query (Software Used: My-SQL VERSION : 8.0)

Database: Master
Table : Student, Fees; Primary Key regno (integer)

1. To create the database ‘Master’.

2. To create the workspace with database Master.


3. To create the table Student as regno (integer) as primary key.

4. Insert records into student.

5.

Display all the records from table student.

6. Modify the name having value ‘RAajat Jha’ of a student whose


registration no is 110.
7. Create a table named fees and display its structure.

8. Insert some records or information into table fees.

9.

Display name, class, date of birth, term and fees from the table
student and fees.
10. Display the card and fees details of students whose name starts
with ‘S’.

11. Display Registration number, name, fees, type of card who has
cleared fees for the first quarter, fees amount in descending order
of their registration number.

12. Display the names of card companies such that no company


should repeat from table fees with a heading COMPANY.
13. Display all the records from table student in descending order
of name for those who have date of birth between 1 st January, 2006
to 31st December 2007.

14. Display term, name of Card providers company and total


collection made by each Card providers in particular quarters from
table “Fees”.

15. Update the address of the students as Asansol have roll number
as 12 in table Student.
16. Using UNION display selective columns from table Student
and fees.

17. Display selective columns where criteria is ‘date of birth within


1st November 2006 and 31st December 2007’ from Student table
and corresponding fees and term from Fees table.
18. Count how many students are there in ‘Asansol’ in table
‘Student’.

19. Calculate the average fees collected in 1 st Quarter in Table


Fees.

20. Calculate
the total
collect made in
Table Fees for
the 1st Quarter.
21. Display all the records where name of the students have been
started with ‘S’ and end with ‘r’.

22. Implement inner join on fees with student in order to display


name, fees, name of the debit card, term and date of birth.
23. Implement left join on fees with student in order to display
class, roll number, name, type of the card in descending order of
student’s name.

24. Display the maximum amount of fees collected for card type
MASTER in table fees.

****

You might also like