0% found this document useful (0 votes)
12 views

pract_12 _IP_practice_A_B

The document contains two sets of programming tasks involving data manipulation using Python and SQL. Set A focuses on creating a DataFrame for cricket players' statistics and performing various operations, while Set B involves creating a DataFrame for students' marks and managing employee records in a database. Each set includes specific tasks such as data creation, querying, and visualization.

Uploaded by

archibaluni
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)
12 views

pract_12 _IP_practice_A_B

The document contains two sets of programming tasks involving data manipulation using Python and SQL. Set A focuses on creating a DataFrame for cricket players' statistics and performing various operations, while Set B involves creating a DataFrame for students' marks and managing employee records in a database. Each set includes specific tasks such as data creation, querying, and visualization.

Uploaded by

archibaluni
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/ 6

Set A

Q1.Consider following data and write a program to do the following: [8]


SNO Batsman Test ODI T20
1 Virat Kohli 3543 2245 1925
2 Ajinkya Rehane 2578 2165 1853
3 Rohit Sharma 2280 2080 1522
4 Shikhar Dhawan 2158 1957 1020
5 Hardik Pandya 1879 1856 980
a) Create a dataframe using Dictionary/lists. 1
b) Count the total number of rows and columns of the dataframe. 1
c) Display the players whose runs inODI are less than 2000. 1
d) Print top 2 rows of dataframe. 1
e) Print last 3 rows of dataframe. 1
f) Plot line /bar chart on name Test . 3

Q2. Consider the following table ITEM write following queries : [7]
ITEM
Column Name Data Type Constraint Name
Item_Code integer Primary key
Item_Name varchar(20)
Price integer
Brand_Name varchar(15)
Write SQL statement to –
(a) Create the above table.
(b) Insert few records in the above table.
e.g.
2001, “Refrigerator”, 8500, “SONY”
2002, “Refrigerator ”, 17500, “LG”
2003, “TV ”, 40000, “ONIDA”
2004, “Computer ”, 60000, “SAMSUNG”
2005, “Smartphone ”, 22500, “SAMSUNG”
2006, “AC ”, 32500, “LG”
2007, “TV ”, 40000, “SONY”

(c) To display Item_code, Item_Name and Brand_Name of those items, whose price is between 20000 and
40000 (both value inclusive).
(d) To display Item_code, Price and Brand_Name of the item, which has Item_Name as “Computer”..
(e) To increase the price of all the items by 10%
(f) To delete the records whose Brand is “ONIDA”.
g) to display the average price of the items.
Solutions Set A
Q1 Write a program for the following : ( Python) [8marks]

import pandas as pd

import matplotlib.pyplot as plt

dic1={'Name':["Virat Kohli","Ajinkya Rahane","Rohit Sharma","Shikhar Dhawan","Hardik Pandya"],

'Test':[3543,2578,2280,2158,1879],

'ODI':[2245,2165,2080,1957,1856],

'T20':[1925,1853,1522,1020,980]

Srno=[1,2,3,4,5]

df1=pd.DataFrame(dic1,index=Srno)

print(df1)

total_row=len(df1.axes[0])

total_col=len(df1.axes[1])

print ("Total Rows: ",total_row)

print ("total columns:",total_col)

print("ODI run less than 2000")

print(df1[df1.ODI>2000])

print("Top 2 rows :",df1.head(2))

print("Last 3 lrows: ",df1.tail(3))

x=df1['Name']

y=df1['Test']

plt.plot(x,y)

plt.title(" Chart")

plt.xlabel("Names")

plt.ylabel("Runs in Test")

plt.show()
Q2 SQL commands (7marks) Solutions
mysql> create database pract1;

mysql> use pract1

(a) Create the above table.


mysql> create table items

(item_code integer primary key,

item_name varchar(20) not null,

price integer integer,

Brand_name varchar(20)

);

(b) Insert few records in the above table.


mysql> insert into items values ( 2001, “Refrigerator”, 8500, “SONY”);
mysql> insert into items values (2002, “Refrigerator”, 17500, “LG” );

mysql> insert into items values (2003, “TV”, 40000, “ONIDA” );

mysql> insert into items values ( 2004, “Computer ”, 60000, “SAMSUNG”);

mysql> insert into items values (2005, “Smartphone”, 22500, “SAMSUNG” );

mysql> insert into items values (2006, “AC”, 32500, “LG” );

mysql> insert into items values (2007, “TV”, 40000, “SONY” );

(c) To display Item_code, Item_Name and Brand_Name of those items, whose price is between 20000
and 40000 (both value inclusive).
Mysql> Select item_code,item_name, Brand_name from items where price between 20000 and 40000;

(d) To display Item_code, price and Brand_name of the item, which has item_name as “Computer”.
Mysql> Select item_code,price, Brand_name from items where item_name=”Computer”;

(e) To show the minimum and maximum price brand wise .


Mysql> update item set price =price+(price*10/100);

(f) To delete the records whose Brand is “ONIDA”.


Mysql> Delete from items where brand_name=”ONIDA”;
g) to display the average price of the items.
Mysql> select avg(price) from items;
Set B

Q1 Write a program for the following : [8]


a)Create a dataframe using Dictionary/lists.1
b)Count the total Number of Rows and columns of Dataframe.[1]
c)Display the students whose marks are less than 550. 1
d)Print top 2 rows of dataframe. 1
e)Print last 3 rows of dataframe. 1
f)Plot a Bar chart /Line chart. 3
Name Class Gender City Marks
1 Naman XII M Anand 453
2 Nandini X F Baroda 551
3 Nakshatr X F Baroda 553
a
4 Shailesh XI M Surat 458
5 Trisha XII F Anand 430
6 Manisha XII F Anand 530
7 Hetvee XII F Junagadh 555
8 Neel X M Godhara 559
9 Mayur XII M Surat 570
Q2. Consider the following table EMPLOYEE and SALARY write following queries : [7]
EMPLOYEE
Column Name Data Type Constraint Name
Emp_num integer Primary key
Emp_nm varchar(20) Not Null
Emp_add varchar(25)
Department varchar(15) (as Sales, Purchase and Accounts)
salary integer

Write SQL statement to –


(a) Create the above table.
(b) Insert few records in the table. eg.
1001,"Deepak","31 Ram Nagar Jaipur","sales",25000
1002,"Pankaj","Jodhpur","purchase",35000

1003,"Ajay","Rampur","sales",51000

1004,"Sanjay","Jodhpur","account",51000

1005,"Vijay","Jaipur","purchase",48000

1006,"Shobhit","Jodhpur","account",31000

(c) To update the salary of employees in purchase department by 10%.


(d) To display all employees’ information in increasing order of their salaries.
(e) To display all the employee’s name length and first 3 character
(f)Display all the records whose salary is greater than 35000 and less than 55000.
(g) To show the minimum and maximum salary on the basis of department wise .

Solutions Set B
Q1 Write a program for the following : ( Python)[8 marks]

import pandas as pd

import matplotlib.pyplot as plt

dic1={'Name':["Naman","Nandini","Nakshatra","Shailesh","Trisha","Manisha",'Hetvee','Neel','Mayur'],
'Class':['XII','X','X','XI','XII','XII','XII','X','XII'],

'Gender':['M','F','F','M','F','F','F','M','M'],

'City':['Anand','Baroda','Baroda','Surat','Anand','Anand','Junagardh','Godhara','Surat'],

'Marks':[453,551,553,458,430,530,555,559,570]

rno=[1,2,3,4,5,6,7,8,9]

df1=pd.DataFrame(dic1,index=rno)

print(df1)

total_row=len(df1.axes[0])

total_col=len(df1.axes[1])

print ("Total Rows: ",total_row)

print ("total columns:",total_col)

print("ODI run less than 2000")

print(df1[df1.Marks<550])

print("Top 2 rows :",df1.head(2))

print("Last 3 lrows: ",df1.tail(3))

x=df1['Name']

y=df1['Marks']

plt.plot(x,y)

plt.title(" Chart")

plt.xlabel("Names")

plt.ylabel("Marks")

plt.show()
Q2 SQL Commands Solutions (7marks)
MYSQL> create database pract1;

mysql> use pract1

(a) Create the above table.


mysql> create table employee

(Emp_num integer primary key,

Emp_nm varchar(20) not null,

Emp_add varchar(25),

department varchar(15),

salary integer

);

(b) Insert few records in the table.


mysql> insert into employee values (1001,"Deepak Mishra","31 Ram Nagar Jaipur","sales",25000);

mysql> insert into employee values (1002,"pankaj","Jodhpur","purchase",35000);

mysql> insert into employee values (1003,"ajay","rampur","sales",51000);

mysql> insert into employee values (1004,"sanjay","Jodhpur","account",51000);

(c) To update the salary of employees in purchase department by 10%.


mysql> Update employee Set salary=salary+(10*salary/100) Where department=”purchase”;
(d) To display all employees’ information in increasing order of their salaries.
mysql> select * from employee order by salary;

(e) To display all the employee’s name length and first 3 character
mysql> select * from employee where department="accounts";

(f)Display all the records whose salary is greater than 35000 and less than 55000.
mysql> select * from employee where salary between 35000 and 55000;

(g) To show the minimum and maximum salary on the basis of department wise .
mysql> select department,min(salary),max(salary) from employee group by department;

You might also like