Lab Record IP
Lab Record IP
Code:
import pandas as pd
import numpy as np
print("**** ND-Array ****")
nd = np.arange(1,6)
print(nd)
print("****Series object****")
s = pd.Series(nd)
print(s)
print("***Series object is created from nd-array***")
Output:
2. Create a Data Frame 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.
Code :
import pandas as pd
data={'Category':['M', 'G', 'C '],'Item Name':['S' ,'S1', 'T'],
'Expenditure':[1500,5000,5100]}
quarterly_sales=pd.DataFrame(data)
print(quarterly_sales)
c=quarterly_sales.groupby('Category')
print('Result after filtering')
print(c['Category','Expenditure'].sum())
Output:
Category ItemName Expenditure
0 M S 1500
1 G S1 5000
2 C T 5100
3. Create a data frame for examination result and display row labels, column labels
data types of each column and the dimensions.
Code:
import pandas as pd
marks = , “English” : *68,95,85,75+, “IP” : *90,80,70,80+, “Accountancy” : *55,67,85,89+,
“Economics”: *85,87,86,85+, “BSt” : *69,89,85,96+,
“Total_Marks” : *367,418,411,425], “Percentage” :*73.4, 83.6, 82.2, 85]
result = pd. DataFrame (marks, index = *“A1”, “B1”,”C1”,”D1”+)
print (result)
print (“ ROW LABEL “)
print (“result.index)
print (“ COLUMN LABEL “)
print (result.columns)
print (“ DIMENSIONS “)
print (result.ndim)
print (“ DATA TYPES “)
print(result.dtypes)
Output:
English IP Accountancy Economics BSt
A1 68 90 55 85 69
B1 95 80 67 87 89
C1 85 70 85 86 85
D1 75 80 89 85 96
ROW LABEL
COLUMN LABEL
DIMENSIONS
DATA TYPES
English int64
IP int64
Accountancy int64
Economics int64
BSt int64
dtype: object
Output:
Name Marks
0 Amit 81
1 Rohit 72
3 Amit 58
4 Rohit 96
5. Importing and exporting data between pandas and CSV file
Code:
import pandas as pd
df = pd.read_csv(“E:\emp.csv”)
print(df)
output:
empid ename doj
0 A01 Bhaskar pal 01-01-2018
1 A02 Shelza ray 01-03-2016
2 A03 Renu takkar 06-05-2019
Code:
import pandas as pd
df1 = *,‘Name’: ‘Bhaskar’, ‘SirName’: ‘pal’-,
,‘Name’: ‘Shelza’, ‘SirName’: ‘ray’-,
,‘Name’: ‘Renu’, ‘SirName’: ‘takkar’-+
df2 = pd.DataFrame(df1)
df2.to_csv(“E:\emp.csv”)
Output:
Name Sirname
0 Bhaskar pal
1 Shelza ray
2 Renu takkar
6. Given a Series, print all the elements that are above the 75th percentile.
Code:
import pandas as pd
import numpy as np
s=pd.Series(np.array([2,4,5,10,18,20,25]))
print(s)
res=s.quantile(q=0.75)
print()
print('75th Percentile of the series is::')
print(res)
print()
print('The elements that above the 75th percentile:')
print(s[s>res])
Output:
0 2
1 4
2 5
3 30
4 18
5 20
6 25
dtype: int64
75th Percentile of the series is:
22.5
7. Given the school result data, analyses the performance of the students on different
parameters, e.g subject wise or class wise.
8. For the Data frames created above, analyze, and plot appropriate charts with title and
legend.
9. Take data of your interest from an open source (e.g. data.gov.in), aggregate and
summarize it. Then plot it using different plotting functions of the Matplotlib library.
Code:
import pandas as pd
import matplotlib.pyplot as plt
dframe=pd.read_csv("D:\Covid_Vaccine.csv")
print(dframe)
output:
Code:
import pandas as pd
import matplotlib.pyplot as plt
dframe=pd.read_csv("D:\Covid_Vaccine.csv")
slices=(dframe['TOTAL DOSES ADMINISTERED'].head(6))
states=(dframe['STATE/UTS'].head(6))
colours=['c','b','y','m','r','gold']
exp=[0,0,0,0,0,0.1]
plt.pie(slices, labels=states, colors=colours, startangle=90, explode=exp, shadow=True,
autopct='%.1f%%')
plt.title('Vaccine Adminstrated ')
plt.legend()
plt.savefig()
plt.show()
Output:
MYSQL:
1. Create a student table with the student id, name, and marks as attributes where the
student id is the primary key.
Query:
Create Table Student
(
Student_Id int Primary key not null,
Name varchar (20) Not null,
Marks int Not null
);
Select * from student where marks > 80 and name like ‘R%’;
5. Find the min, max, sum, and average of the marks in a student marks table.
Minimum Marks:
Select min (Marks) from the student;
Output:
Marks:
365
Maximum Marks:
Select max (Marks) from the student;
Output:
Marks:
485
Sum Marks:
Select sum (Marks) from the student;
Output:
Marks:
1285
Average Marks:
Select avg (Marks) from the student;
Output:
Marks:
428.33
6. Find the total number of customers from each country in the table (customer ID,
customer Name, country) using group by.
Query:
Select country, count(*) “Total Customer”from customer group by
country;
Output:
7. Write a SQL query to order the (student ID, marks) table in descending order of the
marks.
Query:
Select Student_Id, Marks from Student Order by Marks;
8. Write a SQL query to display name, bonus for each employee where bonus is 10% of
salary from employee table.
Query:
Select name, salary * 0.10 as bonus from Employee;
9. Write a SQL query to display Gname, Gcode, Price from Cloth table where price
between 1000 and 1500.
Query:
Select Gname, Gcode, Price from cloth where price between 1000 and
1500;
10.Write a SQL query to display Gcode, Gname from Cloth table where gname sarts from
‘Ram’.
Query:
Select Gcode, Gname From Cloth where Gname like ‘Ram%’;