Professional Documents
Culture Documents
SILIGURI
AFFILIATION CODE: 2430126
NAME:
ROLL NO:
STD: XII STREAM: SCIENCE
INDEX
ASSIGNMENT TOPIC PAGE NO.
NO.
1 Creation of DataFrame; Adding and deleting a Column
Write a program to create a DataFrame. Add a column Total into it and delete the column SST.
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
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
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
print (df)
Output
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
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
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
Output
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']
Output
Write a program to create a csv file in MS-Excel by using a DataFrame as a Data source.
import pandas as pd
import csv
with open("person2.csv", 'r') as file:
csv_file = csv.DictReader(file)
for row in csv_file:
print(dict(row))
Output
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.
Output of Assignment 10
Assignment 11 Dt: 20.07.22
Output
df = pd.DataFrame(data,columns = ['Colors','Shapes'])
print(df)
df = df.rename(columns = {'Colors':'Shapes','Shapes':'Colors'})
print (df)
Output
Write a program to remove a column in an existing DataFrame and to describe other details of the
DataFrame.
#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
#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
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:
Write a program using Matplotlib to draw a bar graph to display the percentage of students in annual
examination in an institution.
Output
Assignment 18 Dt: 01.09.22
Write a program using Matplotlib to draw a bar graph to display the consumption of coffee in a Coffee
Shop.
Output
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)
5.
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.
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.
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’.
24. Display the maximum amount of fees collected for card type
MASTER in table fees.
****