You are on page 1of 14

VEL’S PUBLIC SCHOOL

GRADE- XII
INFORMATICS PRACTICES LAB MANUAL
2022-2023
PYTHON & MYSQL

1. Write a program to create Pandas series from dictionary of values and nd array.

Creation of pandas Series object from dictionary

Program Logic:

● Step 1: Import pandas module in program using import statement


● Step 2: Create Dictionary object with different set of key value pair
● Step 3: Create Series object using dictionary object that we have created in step 2
● Step 4: Display Series object using print function

Below is implementation code/Source code:

Output:

Creating Pandas Series Object from ndarray

● Step 1: Import Pandas module in program using import statement


● Step 2: Import numpy module in program using import statement
● Step 3: Create ndarray with different set of values and store it in some variable
● Step 4: Display ndarray object using print function
● Step 5: Create Series object from ndarray that we have created in Step3
● Step 6: Print Series object using print function

Below is implementation code/Source Code:

Output:

2. Write a program to generate a series of float numbers from 41.0 to 60.0 with an increment of
2.5.
3. Write a program to generate a series of 10 numbers with a scalar value of 44.
4. Write a program to create Pandas DataFrame from dictionary of values and Series.
5. Write a Pandas program to count the number of rows and columns of a Data Frame.

Program Logic:

● Create Dictionary say ‘marks’ which store marks of 5 subject.


● Create Data Frame say ‘result’ which store the marks of 5 students using DataFrame
method.
● Display Data frame ‘result’ using print function.
● Find total number of rows in given data frame using len method and pass result.axes[0] as
an argument to len method
● Store it into another variable total_rows
● Find total number of rows in given data frame using len method and pass result.axes[1] as
an argument to len method
● Store it into another variable total_cols
● Convert calculated data into string using str function.
● Display output using print function
● Exit.

Below is implementation code /Source code

Output:

6. Write a program to perform mathematical operation on two Pandas series object.

Program Logic:

● Create two Series object using series method say s1,s2


● Perform addition operation on two series object using arithmetic operator “+” and store
result in variable ‘addition’
● Perform subtraction operation on two series object using arithmetic operator “-” and store
result in variable ‘subtraction’.
● Perform multiplication operation on two series object using arithmetic operator “*” and
store result in variable ‘multiply’
● Perform division operation on two series object using arithmetic operator “/” and store
result in variable ‘division’
● Perform modulus operation on two series object using arithmetic operator “%” and store
result in variable ‘modulus’
● Print all the variable on output screen using print function for each variable.

Below is implementation code/Source code


Output:

7. Write a program to create data frame for examination result and display row labels, column
labels data types of each column and the dimensions.
Program Logic:

1.Create Dictionary say ‘marks’ which contain marks of 5 subject namely


English,Maths,IP,Chemistry,Biology and total marks obtained and percentage of students
2.Create DataFrame say ‘result’ using DataFrame method of pandas library
3.Print the marksheet of 4 student
4.Use index attribute of DataFrame method to display row labels of dataframe named ‘result’
5.Use columns attribute of DataFrame method to display column labels of dataframe named
‘result’
6.Use dtypes attribute of DataFrame method to display data types of each column
7.Use ndim attribute of DataFrame method to display dimension of dataframe named ‘result’
8.Use shape attribute of DataFrame method to display shape of dataframe named ‘result’
9.Exit
SOURCE CODE:

OUTPUT:
8. Create the following DataFrame Sales containing year wise sales figures for five salespersons
in INR. Use the years as column labels, and salesperson names as row labels.

1. Create the DataFrame.

2. Display the row labels of Sales.

3. Display the column labels of Sales.

4. Display the data types of each column of Sales.

5. Display the dimensions, shape, size and values of Sales.

9. Create a dataframe and iterate them over rows.

Source Code:

import pandas as pd

data = [["Virat",55,66,31],["Rohit",88,66,43],["Hardik",99,101,68]]

players = pd.DataFrame(data,columns = ["Name","Match-1","Match-2","Match-3"])

print("Iterating by rows:")

print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

for index, row in players.iterrows():

print(index, row.values)

print("Iterating by columns:")

print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

for index, row in players.iterrows():

print(index, row["Name"],row["Match-1"],row["Match-2"],row["Match-3"])
OUTPUT:

10. Create a dataframe and print it along with their index using iteritems().

SOURCE CODE:

import pandas as pd

def df_operations():

sc_4yrs={2016:{'Virat Kohli':2595,'Rohit Sharma':2406,'Shikhar Dhawan':2378},

2017:{'Virat Kohli':2818,'Rohit Sharma':2613,'Shikhar Dhawan':2295},

2018:{'Virat Kohli':2735,'Rohit Sharma':2406,'Shikhar Dhawan':2378},

2019:{'Virat Kohli':2455,'Rohit Sharma':2310,'Shikhar Dhawan':1844}}

df=pd.DataFrame(sc_4yrs)

print(df)

print("------------------------------------------------------------------------")

for (year,runs) in df.iteritems():

print("Year:",year)

print(runs)

df_operations()

OUTPUT:
11. Consider the dataframe and write code using tail(),loc & iloc to do the following:
a. Display the last two rows of Sales.
b. Display the first two columns of Sales.

12. Create a dataframe using the dictionary “result” given below and write code using
head(),loc & iloc to do the following:

exam_data = {'name': ['Manish', 'Dhiraj','Man', 'Dhir'], 'score': [12.5, 91,2.5, 9]}

a. Display the first three rows of result.


b. Display the first two columns of result.
13. Write a program to Export data between dataframe and CSV with practical example

Program Logic:

1. Import pandas module in program using import statement


2. Import numpy module using import statement
3. Create Dictionary object say ‘marks’ with different set of key-value pair
4. Create DataFrame object say ‘result’ using DataFrame method and pass index as
argument to it
5. Print DataFrame ‘result’ using print function
6. Write dataframe object into csv file using to_csv method and pass data frame
object as an argument to it

Below is implementation code/Source code:


OUTPUT:

14. Write a program to import data between pandas and CSV file with Practical Example

Program Logic:

1. Import pandas module in program using import statement


2. Read data from CSV file using read_csv method and pass CSV file say ‘result.csv” as an
argument to it
3. Store data which is read from CSV file in python object say ‘df’
4. Display data as output using print function

Below is implementation code/Source code


OUTPUT:

15. Write a program to analyze the performance of student on different parameters subject
wise or class wise from the given school result data.

Program Logic:

● Import matplotlib.pyplot in program using import statement


● Import pandas module using import statement
● Import numpy module using import statement
● Create Dictionary object using different set of key value pair(i.e. subject and marks
scored )
● Create Dataframe object using DataFrame method and pass index say student name as an
argument to it
● Print DataFrame object using print function
● Plot bar chart using plot method and pass kind = bar as an argument to it
● Show bar chart using show method

Below is implementation code /source code


OUTPUT:
16. Write a program to create a data frame for “players track record” ,analyse and plot with
title and legend for the data frame created above using horizontal bar.
17. Write a program to create a data frame for “Annual Sales report” ,analyse and plot with
title and legend for the data frame created above using Histogram for every 5 years from 2000
to 2020.
18. Write a program to create a data frame for “Employee target performance” , analyse and
plot with title and legend for the data frame created above using line plot.
19. Write a program to create a chart of any CSV dataset by reading the data from CSV file.
20. To generate SQL queries to perform the following functions.

1. Create the database loans.

2. Use database loans.

3. Create table loan_accounts ,Loan_details and insert the appropriate tuples in it.
LOAN_ACCOUNTS

ACCNO CUST_NAME LOAN_AMOUNT INSTALLMENTS INT_RATE START DATE

1 R.K GUPTA 300000 36 12 2009-07-19

2 S.P.VERMA 500000 48 10 2008-03-22

3 K.P.JAIN 300000 36 NULL 2007-03-08

4 M.P.YADAV 800000 60 10 2008-12-06

5 S.P.SINHA 200000 36 13 2010-01-03

6 P.SHARMA 700000 60 13 2008-06-05

7 K.S.DHALL 500000 48 NULL 2000-03-05

LOAN_DETAILS

ACCNO NOMINEE_NAME LOAN_TYPE

1 RANVEER PERSONAL

2 RAHUL VEHICLE

3 HARSHITH PERSONAL

4 SHINY HOME

5 REHA HOME

6 REACHAL VEHICLE

7 ABIJITH VEHICLE

4. Display details of all the loans.

5. Display the accno, cust_name and loan_amount of all the loans.

6. Display details of all the loans with less than 40 installments.

7. Display the accno and loan_amount of all the loans started before 01-04-2009.

8. Display the int_rate of all the loans started after 01-04-2009.

9. Display the details of all the loans whose rate of interest is null.

10.Display the amount of various loans from the table loan_accounts. A loan amount should
appear only once.
11.Display the cust_name and loan_amount for all the loans which do not have number of
installments 36.

12.Display the cust_name and loan_amount for all the loans for which the loan amount is less
than 500000 or int_rate is more than 12.

13.Display the details of all the loans whose rate of interest is in the range 11% to 12%.

14.Display the cust_name and loan_amount for all the loans for which the number of
installments are24, 36, or 48.

15.Display the details of all the loans whose loan_amount is in the range 400000 to 500000.

16.Display the accno, cust_name, loan_amount for all the loans for which the cust_name ends
with “Sharma”.

17.Display the accno, cust_name, and loan_amount for all the loans for which the cust_name
contains ‘a’ as the second last character.

18.Display the details of all the loans in the ascending order of their loan_amount.

19.Display the details of all the loans in the descending order of theirstart_date.

20.Put the interest rate 11.50% for all the loans for which interest rate is null.

21.For each loan replace interest with (loan_amount * int_rate*installments)/12*100.

22.Delete the records of all the loans of “k.p. jain”.

23.Add another category of type char(1) in the loan_accounts table.

24.Display the details of customer name and the nominee name.

25.Display all the details of loan whose loan type is “Vehicle”.

You might also like