Creation of Series Using List, Dictionary & Ndarray
Creation of Series Using List, Dictionary & Ndarray
Creation of Series Using List, Dictionary & Ndarray
Aim:
To create series using list, dictionary and nd-array.
OUTPUT:
SOURCE CODE:
import pandas as pd
s1=pd.Series([1,2,3,4,5,6])
print(s1)
s2=pd.Series({1:'one',2:'two',3:'three'},index=[1,2,3])
print(s2)
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
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
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(result)
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
df = pd.DataFrame(exam_data )
total_rows=len(df.axes[0])
total_cols=len(df.axes[1])
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
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(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(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
df = pd.DataFrame(exam_data )
print(df.iloc[:3])
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
print("Original Series:")
print("sr1:")
print(sr1)
print("sr2:")
print(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
'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:
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.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 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.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 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 random
plt.hist(data)
plt.show()
RESULT:
Thus the program was executed and the output was verified successfully.
EX.NO:
PLOTTING HISTOGRAM
DATE:
AIM:
Q1 AND 2
Q3
Q4
SOURCE CODE :
1.
mysql>create database loans;
2.
mysql>use loans;
3.
4.
->values<1,”r.k.gupta”,300000,36,12.00,”2009-07-19”,null>;
->values<2,”s.p.verna”,500000,48,10.00,”2008-03-22”,null>;
OUTPUT:
Q5
Q6
Q7
SOURCE CODE :
start_date<”2009-04-01”;
OUTPUT:
8.
9.
10.
11.
SOURCE CODE :
instalments = 36;
OUTPUT:
12.
13.
14.
15.
SOURCE CODE :
instalments in<24,36,48>;
loan_amount<500000 or int_rate>12;
14. mysql> Select * from loan_accounts where int_rate >=11 and int_rate<=12;
and 500000;
OUTPUT:
16.
17.
18.
16. mysql>select acc_no,cust_name,loan_amount from loan_accounts where
20.
21.
22.
23.
19. mysql>select * from loan_accounts order by start_date desc;
interest=<loan_amount*int_rate*instalments>/<12*100>;