0% found this document useful (0 votes)
9 views5 pages

# To Add The 4Th Record in Dataframe

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)
9 views5 pages

# To Add The 4Th Record in Dataframe

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/ 5

Q.1. Write a python statement for the questions (i) to (iv).

4
ROLL NAME MARKS

0 101 RAM 93
1 102 SOHAN 82
2 103 KISHAN 66
3 104 NISHANT 75
(i) Create the above DataFrame named student by importing data from a CSV file.

(ii) Add the following record in the above DataFrame. 4, 105, ‘HARSH’, 59
(iii) Store the updated DataFrame into csv file.
(iv) Display the marks detail of Roll no 103.

Ans. 1

import pandas as pd
student=pd.read_csv("C:\\Users\\xiib23\\Desktop\\df.csv")
print(student)
# TO ADD THE 4TH RECORD IN DATAFRAME
student.loc[4,:]=[105,'HARSH',59]
print(student)
#STORING UPDATED DATFRAME INTO CSV
student.to_csv("C:\\Users\\xiib23\\Desktop\\ankit.csv")
# Display the mark detail of roll no. 103
s=student.iloc[2:3,2:3]
print(s)

OUTPUT:
(i)
ROLLNO NAME MARKS
0 101 RAM 93
1 102 SOHAN 82
2 103 KISHAN 66
3 104 NISHANT 75
(ii)
ROLLNO NAME MARKS
0 101.0 RAM 93.0
1 102.0 SOHAN 82.0
2 103.0 KISHAN 66.0
3 104.0 NISHANT 75.0
4 105.0 HARSH 59.0

ankit.csv

(iii)
(iv) MARKS
2 66.0

Q.2. Write a Python program to generate a line chart for the following information: 4
Programming languages: Java, Python, PHP, JavaScript, C#, C++
Popularity: 22.2, 17.6, 8.8, 8, 7.7, 6.7
(i) The line must be show with proper colour, width and marker.
(ii) There Should be proper labels for X and Y axis with their properties.
(iii) The Title of the chart should be ‘Worldwide Popularity of Programming Language ‘.
(iv) Draw the Chart generated in your PC in the Answer Sheet.

Ans - 2
import matplotlib.pyplot as plt
lang = ['Java', 'Python', 'PHP', 'JavaScript', 'C#', 'C++']
popularity = [22.2, 17.6, 8.8, 8, 7.7, 6.7]
plt.plot(lang, popularity, color = 'green', linewidth = 5, linestyle = ‘solid’, marker ='D', markersize = 5,
markeredgecolor = 'red')
plt.xlabel("Programming Languages", fontsize=10, color=’red’)
plt.ylabel("Popularity", fontsize=10, color=’blue’)
plt.title("Worldwide Popularity of Programming Language ", fontsize=20, color=’green’)
plt.show()
Q3. Consider the following table (salesperson) and Write SQL queries for following: 7
SID Name DOB Salary Zone
S101 Ankit 1981-01-22 65000 North
S102 Bhavya 1984-10-19 75000 South
S103 Bhumi 1983-12-04 64000 East
S104 Vruti 1988-04-05 45000 West
S105 Vikas 1987-05-02 58000 South

(i) Create the above table with suitable constraints.


(ii) Insert the above records in table.
(iii) Display the salesperson name’s first two letters whose name ends with ‘i’.
(iv) Display the eldest salesperson name
(v) Display the total salary of salesperson who belongs to South zone.
(vi) Display the count of sales person according area wise.
(vii) Display the name and month name of date of birth of all salesman.
Ans.
(i) create table salesperson(SID varchar(25) Primary key, Name varchar(25),DOB date, Salary int,
Zone varchar(25) );
desc salesperson;
(ii) insert into salesperson values('S101' , 'Ankit' , '1981-01-22',65000,'North' ),
('S102','Bhavya','1984-10-19',75000,'South'), ('S103', 'Bhumi', '1983-12-04',64000,'East'),('S104'
,'Vruti' ,'1988-04-05' ,45000,'West'),('S105' ,'Vikas', '1987-05-02' ,58000,'South') ;
Select * from salesperson;

(iii) Select left(Name,2) from salesperson where Name like "%i";


OUTPUT:
+--------------+
| left(Name,2) |
+--------------+
| Bh |
| Vr |
+--------------+
(iv) Select Name, min(DOB) from salesperson;
OUTPUT:
+-------+------------+
| Name | min(DOB) |
+-------+------------+
| Ankit | 1981-01-22 |
+-------+------------+
(v) Select sum(Salary) from salesperson where Zone="South";
OUTPUT:
+-------------+
| sum(Salary) |
+-------------+
| 133000 |
+-------------+
(vi) Select zone, count(*) from salesperson group by Zone ;
OUTPUT:
+-------+----------+
| zone | count(*) |
+-------+----------+
| East | 1|
| North | 1|
| South | 2|
| West | 1|
+-------+----------+
(vii) Select name, monthname(DOB) from salesperson;
OUTPUT
--------+----------------+
| name | monthname(DOB) |
+--------+----------------+
| Ankit | January |
| Bhavya | October |
| Bhumi | December |
| Vruti | April |
| Vikas | May |
+--------+----------------+

You might also like