0% found this document useful (0 votes)
16 views

Remove (2)

Uploaded by

rg6307550360
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Remove (2)

Uploaded by

rg6307550360
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Python Pandas:- Series

Q1:- Number of students in classes 11


and 12 in three given streams (‘Science’
’Commerce’ and ‘Humanities’) are stored
in two Series objects c11 and 12. Write
code to find total number of students in
classes 11 and 12, stream wise.

Solution :-

Output :-
Q2 :- Answer The Following :-

I ) Write A Code to create 2 Series object


using python sequence
Series 1 :- [10,20,30,40,50,60,70,80)]
Series 2 :- [22,44,56,77,88,99,101,122].
Assume that pandas is imported as alias
name pd.

Solution :-
Q3 :- Answer The Following :-
I ) Write A Code to create a Series object
using a dictionary that stores the number
of students In each section of class 12 in
your school.

II ) Write a Code to create a Series object


using two different words : “I”, ”Am”,
“Crying”, “So”, “Hard”. Assume that
pandas is imported as alias name pd.

Solution :-
Q4 :- Object 1 Population stores the
details of population in four metro cities
of india and object 2 AvgIncome stores
the total avg income reported in prv. Year.
Calculate income Per capita for each of
these metro cities.

Solution :-

Output
Q5 :- Write a code to create a Series
object that stores the contribution
amount as the values and the section
names as the indexes with datatype as
float32. The donation will be doubled.

Solution :-

Output :-
Q6 :- Consider a given Series Subject :-

English 87
Economics 54
Hindi 78
Accountancy 89
Business Studies 67

Write a program in python pandas to


create the series.

Solution :-

Output :-
Python Pandas : DataFrame

Q1 :- Create and display a Dataframe


From a 2D dictionary , Sales , Which
stores the quarter-wise sales as inner
dictionary for 4 years , as shown below:
Sales={‘yr1’:{‘Qtr’:45000,’Qtr2’:54000,’Qtr3’:23000,’Qtr4’:59000},
‘yr2’:{‘Qtr’:46000,’Qtr2’:87900,’Qtr3’:56000,’Qtr4’:81000},
‘yr3’:{‘Qtr’:15000,’Qtr2’:76300,’Qtr3’:85900,’Qtr4’:14800},
‘yr4’:{‘Qtr’:57800,’Qtr2’:91200,’Qtr3’:60900,’Qtr4’:12790}}

Solution :-
Q2 :- Write a program to create a
Dataframe from a list containing
dictionaries of the sales performance of
five zonal offices. Zone names should be
the row labels.

Solution :-

Output :-
Q3 :- Answer the following :-

I ) Write a program to create DataFrame


from a 2d list specify own index labels.

II ) Write a program to create a Dataframe


to store weight , age , and names of 3
people. Print the DataFrame and its
transpose.

Solution :-
Q4 :- Write a program to create a
DataFrame Place With Columns
Population , Hospitals And Schools and
with Index [ Delhi , Mumbai , Kolkata ,
Chennai And Banglore ]

Solution :-

Output :-
Q5 :- From the dtf5 used in the above
question, create another DataFrame and
it must not contain the column
“Population” And the row Banglore.

Solution :-

Output :-
Q6 :-- Write a program to create a
DataFrame Place With Columns
Population , Hospitals And Schools and
with Index [ Delhi , Mumbai , Kolkata ,
Chennai And Banglore ]. Transfer it and
read the same in csv file.

Solution :-
Q7 :- Consider the following DataFrame
Salesdf :-

Target Sales

Zone A 56000 58000


Zone B 87000 70000
Zone C 45000 41500
Zone D 68700 65500

I ) WAP to add a column namely Orders having values


6000,6700,6200 and 6000 respectively for the zones A,B,C,D. The
program should also add a new row for a new zone ZoneE. Add
some dummy values in this row.

Solution :- Output :-
Q8 :- Write a program to create a
DataFrame namely Aid that stores the aid
by NGOs for different states. Transfer the
data in csv file and read the same.

Solution :-
Q9 :- Create a DataFrame based on
ecommerce data and generate
descriptive statistics ( Mean , Median ,
Mode , Quartile And Variance ).

Solution :-

Output :-
Plotting Line Graph

Q1 :- Write a program to plot a line chart


to depict the changing weekly onion
prices five weeks. Give appropriate axes
labels.

Solution :-

Output :-
Q2 :- Write a program to create
DataFrame “ Df “ Having Column as week
and marks. Also plot a line graph for the
same.

Solution :-

Output :-
Plotting Bar Graph

Q1 :- Write A Program to plot a Bar chart


from the medals won by Australia. In the
same chart , plot medals won by India
too.

Solution :-

Output :-
Q2 :- Write a Program To create a
DataFrame “ Tournaments “ Having
column as [ Gold , Silver , Bronze ,
Copper]. Also plot a bar graph from the
medals won by India Only for the same.

Solution :-

Output :-
Plotting Histogram

Q1 :- Prof Awasthi is doing some research in


the field of Environment. For some plotting
purposes , he has generated some data as :-

Mu=100
Sigma=15

X=mu+sigma*numpy.random.randn(10000)

Solution :-
Q2 :- A Survey gathers height and weight of
100 participants and recorded the
participants ages as :-
Ages=[1,1,2,3,5,7,8,9,10,11,13,13,15,16,17, 18,19,20,21,21,23,24,24,24,25,25,25,26,26,
26,27,27,27,27,29,30,30,30,30,31,33,34,34, 34,35,36,36,37,37,38,38,39,40,40,41,41,42,
43,45,45,46,46,47,48,48,49,50,51,51,52,52, 53,54,55,56,57,58,60,61,63,65,66,68,70,72,
74,75,77,81,83,84,87,89,90,91]

Write a program to plot a histogram from


above data with 20 bins.

Solution :-

Output :-
PRATICAL 21
Question 3
Problem statement: Collect and store total medals won by 10 countries in Olympic games
and represent it in form of bar chart with title to compare an analyze data.

Solution:
Source Code:
import matplotlib.pyplot as plt
medals = [213,224,300,59,100,140,256,98,60,24]
country = ['Ger','Itly','USA','Jamca','Japan',
'India','China','Aus','Arg','Ethopia']
plt.bar(country, medals)
plt.title('Olympics Medal Tally')
plt.show()
Screenshot:

Output
PRATICAL 23
Question
Problem 4 Given the school result data, analyses the performance of the student
statement:
on different parameters, e.g. subject wise or class wise. Create a dataframe for the above,
plot appropriate chart with title and legend.
Eng Math Phy Chm IT
9 78 89 69 92 96
10 89 91 84 90 98
11 90 80 76 82 90
12 94 98 90 96 100

Solution:
Source Code:
import pandas as pd
import matplotlib.pyplot as plt

d = {'eng':[78,89,90,94],'math':[89,91,80,98],
'phy':[69,84,76,90],'chm':[92,90,82,96],
'IT':[96,98,90,100]}
df = pd.DataFrame(d,[9,10,11,12])
print(df)
df.plot(kind = 'bar',title = 'Class Wise Marks Analysis',
xlabel = 'Class', ylabel = 'Marks')
df1 = df.T
df1.plot(kind = 'bar',title = 'Subject Wise Marks Analysis',
xlabel = 'Class', ylabel = 'Marks')
plt.legend(loc = 'lower center')
plt.show()
Screenshot:

Output
PRATICAL 24
Question
Problem 5 The following seat bookings are the daily records of a month
statement:
December from PVR cinemas:
124,124,135,156,128,189,200,150,158, 150,200,124,143,142,130,130, 170,
189,200,130, 142,167,180,143,143, 135,156,150,200,189,189,142
Construct a histogram from above data with 10 bin..

Solution:
Source Code:
import pandas as pd
import matplotlib.pyplot as plt
L = [124,124,135,156,128,189,200,150,158,
150,200,124,143,142,130,130, 170,
189,200,130, 142,167,180,143,143,
135,156,150,200,189,189,142]
plt.hist(L)
plt.title("Booking Records @ PVR")
plt.show()

Screenshot:
Output
PRATICAL 25
Question
Problem 6 Take data of your interest from an open source (e.g. data.gove.in),
statement:
aggregate and summarize it. Then plot it using different plotting functions of the Matplotlib
library.
Solution:
Source Code:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv('c:\sample\Crime_data.csv')
print(df)
plt.bar(df.Crime,df.Boys,width = 0.25)
plt.bar(0.25,df.Girls,width = 0.25)
plt.bar(0.5,df.Transgender,width = 0.25)
df.plot(kind = 'bar', x = 'Crime')
df.plot(kind = 'bar', x= 'Crime', y= ['Boys','Girls', 'Transgender'])
plt.show()

Screenshot:

Output
MySQL
Practicals
PRATICAL 26
Question
Problem 1 Create a student table with the student id, name, and marks as
statement:
attributes where the student id is the primary key.

Solution:
Source Code:
create table student
( -> studid int primary key,
-> name varchar(30),
-> marks int
-> );

Screenshot:
PRATICAL 27
Question
Problem 2 In the table ‘student’ created in practical 26, insert the details of new
statement:
students.

Solution:
Source Code:
insert into student values(1, 'sanjay', 67);
mysql> insert into student values(2, 'surendra', 88);
mysql> insert into student values(3, 'Jamil', 74);
mysql> insert into student values(4, 'Rahul', 92);
mysql> insert into student values(5, 'Prakash', 78);

Screenshot:
PRATICAL 28
Question
Problem 3 Write SQL command to get the details of the students with marks
statement:
more than 80.

Solution:
Source Code:
select * from student where marks >=80;

Screenshot:
PRATICAL 29
Question
Problem 4 Write SQL command to Find the min, max, sum, and average of the
statement:
marks in a student marks table..

Solution:
Source Code:
select min(marks) as Min_marks, max(marks) as Max_Marks, sum(marks) as
Total_Marks, avg(marks) as Average_Marks from student;

Screenshot:
PRATICAL 30
Question
Problem 5 Delete the details of a student table created in Practical 26.
statement:

Solution:
Source Code:
Delete from student;

Screenshot:
PRATICAL 31
Question
Problem statement:6 Find the total number of customers from each country in the table
(customer ID, customer Name, country) using group by.

Solution:
Source Code:
select country, count(cname) as 'Total_Customers' from customer
group by country;

Screenshot:
PRATICAL 32
Question
Problem 7 Write a SQL query to order the (student ID, marks) table in descending
statement:
order of the marks.

Solution:
Source Code:
select * from student Order By name DESC;

Screenshot:
PRATICAL 33
Question
Problem 8 for the given table ‘Hospital’ write SQL command to display name all
statement:
patient admitted in month of May.
PID PNAME ADMITDATE DEPT FEES
AP/PT/001 Rahil Khan 21/04/2019 ENT 250
AP/PT/002 Jitendal Pal 12/05/2019 Cardio 400
AP/PT/003 Suman Lakra 19/05/2019 Cardio 400
AP/PT/004 Chandumal Jain 24/06/2019 Neuro 600
.

Solution:
Source Code:
select * from hospital where monthname(admitdate) = 'May';

Screenshot:
PRATICAL 34
Question
Problem 9 for the given table ‘Hospital’ write SQL command to Display patient
statement:
name in upper case with year of admission.
PID PNAME ADMITDATE DEPT FEES
AP/PT/001 Rahil Khan 21/04/2019 ENT 250
AP/PT/002 Jitendal Pal 12/05/2019 Cardio 400
AP/PT/003 Suman Lakra 19/05/2019 Cardio 400
AP/PT/004 Chandumal Jain 24/06/2019 Neuro 600
.

Solution:
Source Code:
Select UPPER(pname) as ‘patient name’, YEAR(admitdate) as ‘admit year’
From hospital;

Screenshot:
PRATICAL 35
Question
Problem 10 for the given table ‘Hospital’ Create sql query to display first four
statement:
letters of the patient name along with length of their name who admitted before may.
PID PNAME ADMITDATE DEPT FEES
AP/PT/001 Rahil Khan 21/04/2019 ENT 250
AP/PT/002 Jitendal Pal 12/05/2019 Cardio 400
AP/PT/003 Suman Lakra 19/05/2019 Cardio 400
AP/PT/004 Chandumal Jain 24/06/2019 Neuro 600
.

Solution:
Source Code:
Select LEFT(pname,4) as ‘pname’, length(pname) as ‘length’
From hospital
Where month(admitdate) < 5;

Screenshot:

You might also like