0% found this document useful (0 votes)
59 views65 pages

Creation of Series Using List, Dictionary & Ndarray

Here are the SQL queries to: 1. Create the database loans: CREATE DATABASE loans; 2. Use database loans: USE loans; 3. Create table loan_accounts: CREATE TABLE loan_accounts ( account_no INT PRIMARY KEY, customer_name VARCHAR(50), loan_amount FLOAT, date_of_sanction DATE ); Let me know if you need any other queries.

Uploaded by

rizwana fathima
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)
59 views65 pages

Creation of Series Using List, Dictionary & Ndarray

Here are the SQL queries to: 1. Create the database loans: CREATE DATABASE loans; 2. Use database loans: USE loans; 3. Create table loan_accounts: CREATE TABLE loan_accounts ( account_no INT PRIMARY KEY, customer_name VARCHAR(50), loan_amount FLOAT, date_of_sanction DATE ); Let me know if you need any other queries.

Uploaded by

rizwana fathima
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/ 65

EX.

NO: CREATION OF SERIES USING LIST, DICTIONARY &


DATE: ndARRAY

Aim:
To create series using list, dictionary and nd-array.
OUTPUT:
SOURCE CODE:

# creating panda series from a list

import pandas as pd

s1=pd.Series([1,2,3,4,5,6])

print(s1)

#creating panda series from dictionary

s2=pd.Series({1:'one',2:'two',3:'three'},index=[1,2,3])

print(s2)

# create panda series from ndarray

import numpy as np

s3=pd.Series(np.array([1,2,3,4,5,6]))

print(s3)

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
BINARY OPERATIONS ON DATAFRAMES
DATE:

Aim:
To perform binary operations between two dataframes
OUTPUT:
SOURCE CODE:
import pandas as pd

student={"unit test-1":[5,6,8,3,10],"unit test-2": [7,8,9,6,15]}

student1={"unit test-1":[3,3,6,6,8],"unit test-2":[7,8,9,6,15]}

ds=pd.DataFrame(student)

ds1=pd.DataFrame(student1)

print(ds)

print(ds1)

print("subtraction")

print(ds.sub(ds1))

print("rsub")

print(ds.rsub(ds1))

print("addition")

print(ds.add(ds1))

print("radd")

print(ds.radd(ds1))

print("multiplication")

print(ds.mul(ds1))

print("division")

print(ds.div(ds1))

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
SORTING OF DATA
DATE:

Aim:
To create a series and sort the values of the series
OUTPUT:
SOURCE CODE:

import pandas as pd

s = pd.Series([400, 300.12,100, 200])

print("Original Data Series:")

print(s)

new_s = pd.Series(s).sort_values()

print(new_s)

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
QUANTILE FUNCTION ON SERIES
DATE:

Aim:
To print elements that are above 75th percentile in the given series .
OUTPUT:
SOURCE CODE:

import pandas as pd

import numpy as np

s=pd.Series(np.array([1,2,3,4,5,6,7]))

print(s)

result=s.quantile(0.75)

print("75th percentile of the series is")

print(result)

print("The elements that are above 75th percentile:”)

print(s[s>result])

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: COUNT NUMBER OF ROWS AND COLUMNS OF
DATAFRAME
DATE:

Aim:
To create Pandas program to count the number of rows and columns of a
DataFrame.
OUTPUT:
SOURCE CODE:
import pandas as pd

import numpy as np

exam_data = {'name': ['Manish', 'Dhiraj','Man', 'Dhir'],

'score': [12.5, 91,2.5, 9]}

df = pd.DataFrame(exam_data )

total_rows=len(df.axes[0])

total_cols=len(df.axes[1])

print("Number of Rows: "+str(total_rows))

print("Number of Columns: "+str(total_cols))

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: CREATION OF DATAFRAME AND USING THE
DATE: FUNCTIONS:GROUP AND SUM

Aim:
To create a dataframe of quarterly sales where each row contains the item
category ,item name ,and expenditure, group the rows by the category and print
the total expenditure per category.
OUTPUT: :
SOURCE CODE:

import pandas as pd

qs=pd.DataFrame({"Itemcategory":["cosmetics","babycare","stationary",

"cosmetics","babycare","stationary","cosmetics","babycare","stationary","cosmetics","babyc

are","stationary"], "Itemname":["Nivea face wash","hbbabysoap","parkerpen","hi

lipstick","pampers","apsarapencil", "hi eyeliner","woodwards","camlin cryons", "hi

sunscreenlotion","oil","camlinset"],"expenditure":[1000,2000,3000,3200,4300,2300,2100,22

00,4300,1200,980,1280]})

print(qs)

result=qs.groupby('Itemcategory')

print('')

print("Results after filtering dataframe")

print(result['Itemcategory','expenditure'].sum())

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: CREATION OF DATAFRAME AND USING THE
DATE: FUNCTIONS: DTYPE AND SHAPE

Aim:
To create a data frame for examination result and display row labels
,column labels ,data types of each column and the dimensions.
OUTPUT:
SOURCE CODE:

import pandas as pd

dic={'Class':['I','II','III','IV','V','VI','VII','VIII','IX'],

'Pass_Percentage':[100,100,100,100,100,100,100,100,100]}

result=pd.DataFrame(dic)

print(result)

print(result.dtypes)

print("shape of the dataframe::")

print(result.shape)

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
HEAD AND ILOC FUNCTION
DATE:

Aim:
To create Pandas program to get the first 3 rows of a given DataFrame.
OUTPUT:
SOURCE CODE:

import pandas as pd

exam_data = {'name': ['Manish', 'Dhiraj','Man', 'Dhir'],

'score': [12.5, 91,2.5, 9]}

df = pd.DataFrame(exam_data )

print("First three rows of the data frame:")

print("using iloc function")

print(df.iloc[:3])

print("using head function")

print(df.head(3))

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
ELIMINATION OF DUPLICATE ROWS
DATE:

Aim:
To filter out rows based on different criteria such as duplicate rows.
OUTPUT:
SOURCE CODE:

import pandas as pd

d1={'NAME':['Abi','Prathanya','Akilan','Kavya','Sendhan','Prathanya','Kavya'],

'MARKSINIP':[89,87,78,67,90,87,67]}

df=pd.DataFrame(d1)

duplicaterow=df[df.duplicated(keep=False)]

print(duplicaterow)

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
UNION AND INTERSECTION FUNCTION
DATE:

Aim:
To create pandas series and to get the items which are not common of
two given series.
OUTPUT:
SOURCE CODE:

import pandas as pd

import numpy as np

sr1 = pd.Series([1, 2, 3])

sr2 = pd.Series([2, 3, 6])

print("Original Series:")

print("sr1:")

print(sr1)

print("sr2:")

print(sr2)

print("\nItems of a given series not present in another given series:")

sr11 = pd.Series(np.union1d(sr1, sr2))

sr22 = pd.Series(np.intersect1d(sr1, sr2))

result = sr11[~sr11.isin(sr22)]

print(result)

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: IMPORTING AND EXPORTING DATA BETWEEN
DATE: PANDAS AND CSV FILE

Aim:
To import and export data between pandas and csv file.
OUTPUT:
#import

#export
SOURCE CODE:

import pandas as pd

qs=pd.DataFrame({'Itemcategory':['cosmetics','babycare','stationary','cosmetics','babycare','sta

tionary', 'cosmetics','babycare','stationary', 'cosmetics','babycare','stationary'],

'Itemname':['Nivea face wash','hbbabysoap','parkerpen', 'hi lipstick','pampers','apsarapencil',

'hi eyeliner','woodwards','camlin cryons', 'hi sunscreenlotion','oil','camlin set'],

'expenditure':[1000,2000,3000,3200,4300,2300,2100,2200,4300,1200,980,1280]})

print(qs)

qs.to_csv("C:\Users\VELS\Desktop\grade 12 IP\pythonpandas.csv")

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: 7 SIMPLE PLOTTING OF BAR GRAPH USING DATA
DATE: VISUALISATION

Aim:
To plot the given school result data ,analyse the performance of the
students on different parameters.
OUTPUT:
SOURCE CODE:

import matplotlib.pyplot as plt

subject=['maths','physics','chemistry','biology','ip','english']

percentage=[90,89,97,89,91,92]

plt.bar(subject,percentage,align='center',color='blue')

plt.xlabel('subjectname')

plt.ylabel('passpercentage')

plt.title('bar graph for result analysis')

plt.show()

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: 8
PLOTTING USING LEGEND AND TITLE
DATE:

Aim:
To analyse, and plot appropriate charts with title and legend for the data
frame created above .
OUTPUT:
SOURCE CODE:

import matplotlib.pyplot as plt

import numpy as np

s=['1st','2nd','3rd']

per_sc=[89,78,90]

per_com=[90,79,82]

per_hum=[89,78,88]

x=np.arange(len(s))

plt.bar(x,per_sc,label='science',width=0.25,color='orange')

plt.bar(x+.25,per_com,label='commerce',width=0.25,color='pink')

plt.bar(x+.50,per_hum,label='humanities',width=0.25,color='gold')

plt.xticks(x,s)

plt.xlabel('position')

plt.ylabel('percentage')

plt.title('bar graph for result analysis')

plt.legend()

plt.show()

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO: 9
PLOTTING USING DATA FROM CSV FILE
DATE:

Aim:
To aggregate and summarize data from open source as csv and plotting
graph on collected information.
OUTPUT:
SOURCE CODE:

import matplotlib.pyplot as plt

import pandas as pd

df=pd.read_csv("C:\Users\VELS\Desktop\grade 12 IP\coviddata.csv")

print(df)

newcase=(df['new'].head(5))

district=(df['District'].head(5))

dis=(df['discharge'].head(5))

death=(df['deaths'].head(5))

plt.plot(district,newcase)

plt.plot(district,dis)

plt.plot(district,death)

plt.title("covid data")

plt.legend()

plt.show()

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
PLOTTING HISTOGRAM
DATE:

Aim:
To create a histogram using random numbers
OUTPUT:
SOURCE CODE:

import matplotlib.pyplot as plt

import random

data = [random.randint(1, 100) for _ in range(100)]

plt.hist(data)

plt.show()

RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
PLOTTING HISTOGRAM
DATE:

AIM:

To generate SQL queries to perform the following functions.

1. Create the database loans.


2. Use database loans.
3. Create table loan_accounts and insert tuples in it.
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 are 24, 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 their start_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
OUTPUT:

Q1 AND 2

Q3

Q4
SOURCE CODE :

1.
mysql>create database loans;

2.

mysql>use loans;

3.

mysql>create table loan_accounts

-><accno integer,cust_name varchar(30),loan_amount

decimal,instalments integer,int_rate decimal,start_date date,interest integer>;

4.

mysql> insert into loan_accounts

->values<1,”r.k.gupta”,300000,36,12.00,”2009-07-19”,null>;

mysql> insert into loan_accounts

->values<2,”s.p.verna”,500000,48,10.00,”2008-03-22”,null>;
OUTPUT:

Q5

Q6

Q7
SOURCE CODE :

5. mysql> Select accno,cust_name,loan_amount from loan_accounts;

6. mysql> select * from loan_accounts where instalments<40;

7.mysql>select accno,loan_amount from loan_accounts where

start_date<”2009-04-01”;
OUTPUT:
8.

9.

10.
11.

SOURCE CODE :

8. mysql> Select int_rate from loan_accounts where start_date>”2009-04-01”;

9. mysql>select* from loan_accounts where int_rate is null;

10. mysql>Select distinct loan_amount from loan_accounts;

11. mysql> select cust_name,loan_amount from loan_accounts where not

instalments = 36;
OUTPUT:

12.

13.

14.
15.

SOURCE CODE :

12. mysql> Select cust_name,loan_amount from loan_accounts where

instalments in<24,36,48>;

13.mysql> select cust_name,loan_amount from loan_accounts where

loan_amount<500000 or int_rate>12;

14. mysql> Select * from loan_accounts where int_rate >=11 and int_rate<=12;

15. mysql> Select * from loan_accounts where loan_amount between 400000

and 500000;
OUTPUT:

16.

17.

18.
16. mysql>select acc_no,cust_name,loan_amount from loan_accounts where

cust_name like “%sharna”;

17.mysql>select acc_no,cust_name,loan_amount from loan_accounts where

cust_name like “%sharna”;

18. mysql>select * from loan_accounts order by loan_amount;


19.

20.

21.

22.

23.
19. mysql>select * from loan_accounts order by start_date desc;

20. mysql>update loan_accounts set int_rate =11.50 where int_rate is null;

21. mysql>update loan_accounts set

interest=<loan_amount*int_rate*instalments>/<12*100>;

22. mysql>delete from loan_accounts where cust_name =”k.p.jain”;

23.mysql>alter table loan_accounts add category char (1);

You might also like