Matplotlib linechatsy
Matplotlib linechatsy
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 :-
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.
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 :-
Outpu
t
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
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 :-
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
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
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
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
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]
Solution :-
Output :-
PRATICAL 21
ProQbluemessttaitoenme3nt: 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
ProQbleumessttaitoemne4nt: Given the school result data, analyses the
performance of the student on different parameters, e.g. subject wise or class
wise. Create a dataframe for the above, plot appropriate chart with title and
Eng Math Phy Chm IT
legend.
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
ProbQleumesstattieomnen5t: The following seat bookings are the
daily records of a month 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
ProQbleumessttaitoemne6nt: Take data of your interest from an open source
(e.g. data.gove.in), 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
ProQbluemessttaiotenme1nt: Create a student table with the student id,
name, and marks as 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
ProQbluemessttaitoemne2nt: In the table ‘student’ created in practical 26,
insert the details of new 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
ProbQlemuesstattieomnen3t: Write SQL command to get the details of the students
Solution:
Source Code:
select * from student where marks >=80;
Screenshot:
PRATICAL 29
ProQbluemessttaiotenme4nt: Write SQL command to Find the min, max, sum, and
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
ProQbluemessttaitoemne5nt: Delete the details of a student table created in
Practical 26.
Solution:
Source Code:
Delete from student;
Screenshot:
PRATICAL 31
ProbQleumesstattieomnen6t: 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
ProQbleumesstattieomnen7t: Write a SQL query to order the (student ID,
marks) table in descending order of the marks.
Solution:
Source Code:
select * from student Order By name DESC;
Screenshot:
PRATICAL 33
ProQbluemessttaitoenme8nt: for the given table ‘Hospital’ write SQL command to display
Solution:
Source Code:
select * from hospital where monthname(admitdate) = 'May';
Screenshot:
PRATICAL 34
ProbQlemuestsattieomnen9t: for the given table ‘Hospital’ write SQL command to
Solution:
Source Code:
Select UPPER(pname) as ‘patient name’, YEAR(admitdate) as ‘admit year’
From hospital;
Screenshot:
PRATICAL 35
ProQbluemessttiaotenme1n0t: for the given table ‘Hospital’ Create sql query
to display first four letters of the patient name along with length of their
PID PNAME ADMITDATE DEPT FEES
name who
AP/PT/001 admitted before
Rahil Khan may. 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: