0% found this document useful (0 votes)
20 views56 pages

Python Programs

This document contains 40 SQL queries to be written based on 4 tables covering topics like selecting data, aggregating results, filtering records, and joining tables. The tables include data about school buses, customers, employees and departments
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views56 pages

Python Programs

This document contains 40 SQL queries to be written based on 4 tables covering topics like selecting data, aggregating results, filtering records, and joining tables. The tables include data about school buses, customers, employees and departments
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Python

programs
30 programs
INDEX
I. To create a series from two different lists.
II. To perform indexing, slicing and accessing data from a
series
III. Usage of loc and iloc for accessing elements of a series.
IV. To create a student CSV file from Dataframe.

V. To illustrate the working of head () and tail () function


on a series.
VI. To create dataframe from two series of student data.
VII. To sort the data of student dataframe based on marks
VIII. Create a dataframe student with columns such as
name of the students, students marks in subjects IP and
BST. Also, rename the column Name as Nm and IP as
Informatics Practices.
IX. Illustrate head () and tail() methods in an Employee
dataframe.
X. Program to concatenate two dataframes.
XI. To get maximum value of all the columns in
pandas dataframe
XII. To get minimum value of all the columns in
pandas dataframe
XIII. To get the total sum of column 'Score'
XIV. To get the total number of entries for 'Name' column
XV. To calculate mode of the dataframe

1|Page
XVI. To calculate mean of every single row containing
numeric value in the dataframe
XVII. To calculate median of the dataframe
XVIII. To implement pivoting using pivot() method for result
dataframe
XIX. Sort the python pandas Dataframe given below on the
basis of a single column in descending order.
XX. To implement groupby() by grouping all the
recordsbased on age and displaying the maximum age
amongst each age group.
XXI. Get the maximum value of all the columns in pandas
dataframe.
XXII. To add legends,titles and labels to a line plot with
multiple lines.
XXIII. Program to plot a quadratic equation using dashed line
chart.
XXIV. To create and open "Employee.csv" file using Pandas.
XXV. To plot lines with different styles using plot () function.
XXVI. To plot a multiple bar chart for section wise students
through pandas dataframe.
XXVII. To plot a simple bar chart orange in colour.
XXVIII. To plot a bar chart horizontally.
XXIX. To plot a histogram using plot () method with 'hist'
argument.
XXX. To plot temperature for 3 consecutive weeks using
a line chart.

2|Page
Program 1. To create a series from two
different lists.

3|Page
Program 2. To perform indexing, slicing and
accessing data from a series.

4|Page
Program 3. Usage of loc and iloc for
accessing elements of a series.

5|Page
Program 4. To create a student CSV file from
Dataframe.

6|Page
Program 5. To illustrate the working of head
() and tail () function on a series.

7|Page
Program 6. To create dataframe from two
series of student data.

8|Page
Program 7. To sort the data of student
dataframe based on marks

9|Page
Program 8. Create a dataframe student with
columns such as name of the students,
students marks in subjects IP and BST. Also,
rename the column Name as Nm and IP as
Informatics Practices.

10 | P a g e
Program 9. Illustrate head () and tail()
methods in an Employee dataframe.

11 | P a g e
Program 10. Program to concatenate two
dataframes.

12 | P a g e
Program 11. To get maximum value of all the
columns in pandas dataframe

13 | P a g e
Program 12. To get minimum value of all the
columns in pandas dataframe

14 | P a g e
Program 13. To get the total sum of
column 'Score'

15 | P a g e
Program 14. To get the total number of
entries for 'Name' column

16 | P a g e
Program 15. To calculate mode of the
dataframe

17 | P a g e
Program 16. To calculate mean of every
single row containing numeric value
in the dataframe

18 | P a g e
Program 17. To calculate median of the
dataframe

19 | P a g e
Program 18. To implement pivoting using
pivot() method for result dataframe

20 | P a g e
Program 19. Sort the python pandas
Dataframe given below on the basis of a
single column in descending order.

21 | P a g e
Program 20. To implement groupby() by
grouping all the recordsbased on age and
displaying the maximum age amongst each
age group.

22 | P a g e
Program 21. Get the maximum value of all
the columns in pandas dataframe.

23 | P a g e
Program 22. To add legends,titles and labels
to a line plot with multiple lines.

24 | P a g e
Program 23. Program to plot a quadratic
equation using dashed line chart.

25 | P a g e
Program 24. To create and open
"Employee.csv" file using Pandas.

26 | P a g e
Program 25. To plot lines with different
styles using plot () function.

27 | P a g e
Program 26. To plot a multiple bar chart
for section wise students through
pandas dataframe.

28 | P a g e
29 | P a g e
Program 27. To plot a simple bar chart
orange in colour.

30 | P a g e
Program 28. To plot a bar chart horizontally.

31 | P a g e
Program 29. To plot a histogram using plot ()
method with 'hist' argument.

32 | P a g e
Program 30. To plot temperature for 3
consecutive weeks using a line chart.

33 | P a g e
34 | P a g e
SQL
QUERY
40 query

35 | P a g e
Table – 1
Consider the given table schoolbus and
answer the questions.

Write the SQL command to get the following:

(i) To show all information of students where capacity


is more than the no. of students in order of rtno.

36 | P a g e
(ii) To show area_covered for buses covering more
than 20 km., but charges less than 80000.

(ii) To show transporter-wise total no. of students


travelling.

37 | P a g e
(iv) To show rtno, area_covered and average cost per
student for all routes where average cost per student
is --- charge / no of students.

(v) Add a new record with the following data:


(11, "Motibagh", 35, 32, 10, "kisan tours", 35000)

38 | P a g e
(vi) Select sum(distance) from school bus where
transporter= "Yadav travels";

(vii) Select min(no of students) from school bus;

39 | P a g e
(viii) Select avg(charges) from school bus where
transporter = "Anand travels";

(ix) Select distinct transporter from school bus;

40 | P a g e
Table – 2
Q. Consider the CUSTOMERS table having
the following records:

Write the SQL command to get the following:


(a) Write an SQL query to display all records in
ascending order of name.

41 | P a g e
(b) Write an SQL query to display all records in
descending order of name.

(c) Write an SQL query to display all records in


ascending order of name and descending order of
age.

42 | P a g e
(d) Write an SQL query to display maximum salary.

(e) Write an SQL query to display minimum salary.

(f) Write an SQL query to display total number of


records.

43 | P a g e
(g) Write an SQL query to display average salary.

(h) Write an SQL query to display total salary of all the


persons.

(i) Write an SQL query to display names of those


persons whose salary is greater than the average
salary.

44 | P a g e
(j) Write an SQL query to display details of those
persons whose age is less than the average age

45 | P a g e
Table – 3
Q. Consider the following EMP and DEPT
tables:

Write the SQL command to get the following:

(a) Show the minimum, maximum and average salary


of managers

46 | P a g e
(b) Count the number of clerks in the organization.

(c) Display the designation-wise list of employees with


name, salary and date of joining.

47 | P a g e
(d) Count the number of employees who are not
getting commission.

(e) Show the average salary for all departments with


more than 5 working people.

(f) List the count of employees grouped by DeptID.

48 | P a g e
(g) Display the maximum salary of employees in each
department.

(h) Count the number of employees working in


ACCOUNTS department.

49 | P a g e
Table – 4
Q. Consider the following table and
answer the questions that follow.

Write the command/output for the


following:

(a) To display all information about the teacher of


PGT category.

50 | P a g e
(b) To list the names of female teachers of Hindi
department.

(c) To list names, departments and date of hiring of all


the teachers in ascending order of date of joining.

51 | P a g e
(d) To count the number of teachers in English
Department.

(e) Display the department and hire date of all the


female teachers whose salary is more than 25000.

(f) Display the list of teachers whose name starts with


J.

52 | P a g e
(g) select count(*) from TEACHER where
Category='PGT';

(h) select avg(salary) from TEACHER group by Gender;

(i) Write a query to add a record of your choice.

53 | P a g e
(j) Write a query to display the names of the female
teachers.

(k) Write a query to increase the salary of all teachers


in English department by 12%

(l) Write a query to display all the records where


annual salary > 120000

54 | P a g e
(m) Write a query to remove all the records of PGT
teachers.

55 | P a g e

You might also like