State whether the following statement is True or False:
Slicing can be used to extract a specific portion from a Pandas Series.
Answer
True
Reason — Slicing can be used to extract a specific portion from a Pandas Series by specifying the start, stop, and step values. The syntax is Series[start:stop:step]
.
For example,
import pandas as pd
data = pd.Series([5, 10, 15, 20, 25, 30, 35])
sliced_data = data[1:5:1]
print(sliced_data)
1 10
2 15
3 20
4 25
dtype: int64
The purpose of WHERE clause in a SQL statement is to:
- Create a table
- Filter rows based on a specific condition
- Specify the columns to be displayed
- Sort the result based on a column
Answer
Filter rows based on a specific condition
Reason — The purpose of the WHERE clause in a SQL statement is to select only those rows that meet a specific condition.
Identify the networking device responsible for routing data packets based on their destination addresses.
- Modem
- Hub
- Repeater
- Router
Answer
Router
Reason — A Router is a networking device responsible for directing data packets to their correct destination by analyzing their destination addresses.
Identify the SQL command used to delete a relation (table) from a relational database.
- DROP TABLE
- REMOVE TABLE
- DELETE TABLE
- ERASE TABLE
Answer
DROP TABLE
Reason — The DROP TABLE
command in SQL is used to delete an entire relation (table) from a relational database, removing its structure and all data permanently.
e-waste refers to:
- Software that has become obsolete
- Data that has been deleted from a storage device
- Viruses that infect computers
- Electronic devices that are no longer in use
Answer
Electronic devices that are no longer in use
Reason — E-waste, or electronic waste, refers to discarded electronic or electrical devices and components. This includes items like computers, mobile phones, televisions, refrigerators, and other electronic appliances that are no longer in use or have reached the end of their life cycle.
Which of the following Python statements can be used to select a column column_name from a DataFrame df ?
- df.getcolumn('column_name')
- df['column_name']
- df.select('column_name')
- df(column_name)
Answer
df['column_name']
Reason — The statement df['column_name']
is used to select a column named column_name
from a DataFrame df
in Python.
By default, the plot() function of Matplotlib draws a ............... plot.
- histogram
- column
- bar
- line
Answer
line
Reason — By default, the plot()
function of Matplotlib draws a line plot, which connects data points with lines.
State whether the following statement is True or False:
In SQL, the HAVING clause is used to apply filter on groups formed by the GROUP BY clause.
Answer
True
Reason — The HAVING clause applies conditions to groups after data is grouped using the GROUP BY clause in SQL queries.
Which of the following Python statements is used to import data from a CSV file into a Pandas DataFrame (Note: pd is an alias for pandas)?
- pd.open_csv('filename.csv')
- pd.read_csv('filename.csv')
- pd.load_csv('filename.csv')
- pd.import_csv('filename.csv')
Answer
pd.read_csv('filename.csv')
Reason — The statement pd.read_csv('filename.csv')
is used to import data from a CSV file into a Pandas DataFrame. The read_csv
function reads the contents of the specified CSV file and converts it into a structured DataFrame format.
What is plagiarism ?
- Using copyrighted material without giving proper acknowledgement to the source
- Downloading illegal software.
- Spreading misinformation online.
- Hacking into computer systems.
Answer
Using copyrighted material without giving proper acknowledgement to the source
Reason — Plagiarism is stealing someone else's intellectual work, such as an idea, literary work or academic work etc., and representing it as our own work without giving credit to creator or without citing the source of information.
Fill in the Blank
The COUNT(*) function provides the total number of ............... within a relation (table) in a relational database.
- Columns
- Unique values
- Not-null values
- Rows
Answer
Rows
Reason — The COUNT(*)
function provides the total number of rows within a relation (table) in a relational database. It counts all rows, including duplicates and NULL values.
In which of the network topologies do all devices connect to a central point, such as a switch or hub?
- Star
- Bus
- Tree
- Mesh
Answer
Star
Reason — Star topology consists of a central node to which all other nodes are connected by a single path.
In a Pandas DataFrame, if the tail() function is used without specifying the optional argument indicating the number of rows to display, what is the default number of rows displayed, considering the DataFrame has 10 entries ?
- 0
- 1
- 4
- 5
Answer
5
Reason — In a Pandas DataFrame, if the tail()
function is used without specifying an optional argument, it displays the last 5 rows by default.
Identify the type of cybercrime that involves sending fraudulent emails to deceive individuals into revealing sensitive information.
- Hacking
- Phishing
- Cyberbullying
- Cyberstalking
Answer
Phishing
Reason — Phishing is the act of illegally acquiring personal and sensitive information such as, online banking details, credit card details, and other login details, of an individual by sending malicious e-mails or by creating web pages that can collect this information as they appear to come from very famous organizations.
While creating a Series using a dictionary, the keys of the dictionary become:
- Values of the Series
- Indices of the Series
- Data type of the Series
- Name of the Series
Answer
Indices of the Series
Reason — While creating a Series using a dictionary, the keys of the dictionary become the indices of the Series. The values in the dictionary correspond to the data in the Series.
Match the following SQL functions/clauses with their descriptions:
SQL Function | Description | ||
---|---|---|---|
P. | MAX() | 1. | Find the position of a substring in a string. |
Q. | SUBSTRING() | 2. | Returns the maximum value in a column. |
R. | INSTR() | 3. | Sorts the data based on a column. |
S. | ORDER BY | 4. | Extracts a portion of a string. |
- P-2, Q-4, R-3, S-1
- P-2, Q-4, R-1, S-3
- P-4, Q-3, R-2, S-1
- P-4, Q-2, R-1, S-3
Answer
P-2, Q-4, R-1, S-3
Reason —
The
MAX()
function is used to return the maximum value from a specified column in a database table.The
SUBSTRING()
function extracts a portion of a string based on specified starting position and length.The
INSTR()
function returns the position of a substring within a string.The
ORDER BY
clause is used to sort the result set based on one or more columns in ascending or descending order.
Fill in the Blank
Boolean indexing in Pandas DataFrame can be used for ...............
- Creating a new DataFrame
- Sorting data based on index labels
- Joining data using labels
- Filtering data based on condition
Answer
Filtering data based on condition
Reason — Boolean indexing in Pandas DataFrame allows for the selection of rows based on a condition that evaluates to True
or False
.
Which Matplotlib plot is best suited to represent changes in data over time?
- Bar plot
- Histogram
- Line plot
- Histogram & Bar plot
Answer
Line plot
Reason — A line plot shows changes over time by connecting data points, called "markers," with straight line segments. A line chart, or line graph, is a type of chart that displays continuous information effectively.
Which type of network covers a small geographical area like a single office, building, or school campus?
- PAN
- MAN
- LAN
- WAN
Answer
LAN
Reason — LAN (Local Area Network) covers a small geographical area like a home, office, or school. It typically covers an area of up to 10 kilometers.
Assertion (A): We can add a new column in an existing DataFrame.
Reason (R): DataFrames are size mutable.
- Both A and R are true, and R is the correct explanation of A.
- Both A and R are true, and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true, and R is the correct explanation of A.
Explanation
We can add a new column to an existing DataFrame using the .at
or .loc
methods. A DataFrame is a two-dimensional data structure that is size-mutable. This means that we can add or drop elements in an existing DataFrame object without needing to create a new DataFrame internally.
Assertion (A): In SQL, INSERT INTO is a Data Definition Language (DDL) Command.
Reason (R): DDL commands are used to create, modify, or remove database structures, such as tables.
- Both A and R are true, and R is the correct explanation of A.
- Both A and R are true, and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is false but R is true.
Explanation
In SQL, INSERT INTO is a Data Manipulation Language (DML) Command. Data definition language (DDL) commands in SQL are used to define a database, including creating, altering, and dropping tables.
What is a Series in Python Pandas? Also, give a suitable example to support your answer.
Answer
In Python Pandas, a Series is a one-dimensional array containing a sequence of values of any data type (such as integers, strings, floats, lists, etc.). It is similar to a column in a spreadsheet. Each element in a Series has a unique label or index, making it easy to access individual values. By default, a Series has numeric labels starting from zero.
An example of a series containing the names of students is given below:
Index Value
0 Adhya
1 Samrat
2 Rohit
3 Dinesh
What does the term 'library' signify in Python? Mention one use for each of the following libraries:
- Pandas
- Matplotlib
Answer
The Python library is an extensive collection of functions and modules that provides functionalities for specific tasks.
Uses of libraries:
Pandas — Used for data analysis.
Matplotlib — Used for data visualization, helping create plots.
What are intellectual property rights (IPR), and why are they important in the digital world?
Answer
Intellectual property rights are the rights of the owner of information to decide how much information is to be exchanged, shared or distributed. Also it gives the owner a right to decide the price for doing so.
Importance of IPR in the digital world :
In the digital world, where content can be easily copied and shared, IPR helps ensure creators are paid fairly for their work and encourages them to create more.
Consider the string: "Database Management System". Write suitable SQL queries for the following:
I. To extract and display "Manage" from the string.
II. Display the position of the first occurrence of "base" in the given string.
Answer
I. SELECT SUBSTRING('Database Management System', 10, 6);
II. SELECT INSTR('Database Management System', 'base');
What is Internet and how does it differ from World Wide Web (WWW)?
Answer
The Internet is a vast network of interconnected computer networks facilitating global communication and data exchange. The World Wide Web (WWW), on the other hand, is a system of interlinked hypertext documents accessed via the Internet.
Explain the concept of browser cookies and mention one advantage of using them.
Answer
Cookies are small text files stored on a user's computer, created and used by websites to remember basic information about the user and personalising their experience.
Cookies improve user experience by remembering preferences, like user's preferred language and other settings.
Define the term Primary Key in a database. Explain how it is different from a Candidate Key.
Answer
A primary key is a set of one or more attributes/fields that can uniquely identify tuples/rows within the relation (table). It must contain unique values and cannot be null.
A candidate key, on the other hand, refers to all the attributes in a relation that are candidates or are capable of becoming a primary key. A table can have multiple candidate keys, but only one of them is chosen as the primary key.
Mention two health concerns associated with excessive use of Digital Devices.
Answer
The two health concerns associated with excessive use of digital devices are as follows:
Impact on Hearing — Listening to loud music for over 15 minutes can cause hearing damage. Using headphones for long periods increases bacteria in the ears by over 700 times.
Impact on Bones and Joints — Technology affects posture due to prolonged sitting and repetitive movements, leading to muscle and joint strain. Repetitive Strain Injuries (RSIs) affect muscles, nerves, tendons, ligaments, and joints.
Sneha is writing a Python program to create a DataFrame using a list of dictionaries. However, her code contains some mistakes. Identify the errors, rewrite the correct code, and underline the corrections made.
import Pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28}
data = [D1, D2, D3)
df = pd.Dataframe(data)
print(df)
Answer
import Pandas as pd # Error 1
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha", 'Age': 28} # Error 2
data = [D1, D2, D3) # Error 3
df = pd.Dataframe(data) # Error 4
print(df)
Error 1 — The module should be imported as import pandas as pd
(lowercase).
Error 2 — In D3
, the value has mismatched quotes.
Error 3 — The list data should use square brackets [], not parentheses.
Error 4 — The Dataframe should be DataFrame (capital 'F').
The corrected code is:
import pandas as pd
D1 = {'Name': 'Rakshit', 'Age': 25}
D2 = {'Name': 'Paul', 'Age': 30}
D3 = {'Name': 'Ayesha', 'Age': 28}
data = [D1, D2, D3]
df = pd.DataFrame(data)
print(df)
Complete the given Python code to get the required output (ignore the dtype attribute) as
Output:
Tamil Nadu Chennai
Uttar Pradesh Lucknow
Manipur Imphal
Code:
import _______ as pd
data = ['Chennai','_______','Imphal']
indx = ['Tamil Nadu','Uttar Pradesh','Manipur']
s = pd.Series(_______, indx)
print(_______)
Answer
import pandas as pd
data = ['Chennai', 'Lucknow', 'Imphal']
indx = ['Tamil Nadu','Uttar Pradesh','Manipur']
s = pd.Series(data, indx)
print(s)
Ayesha's family is replacing their old computer with a new one. They decide to throw the old computer in a nearby empty field/plot.
I. Explain any one potential environmental hazard associated with improper e-waste disposal.
II. Suggest one responsible way to Ayesha's family for proper disposal of their old computer.
III. Describe the importance of recycling in e-waste management.
Answer
I. E-waste contains hazardous substances such as lead, mercury, cadmium, arsenic etc. Improper handling or disposal of e-waste can release these toxic substances into the environment, leading to various health hazards including lung cancer, DNA damage, and brain damage.
II. They can donate or sell it to a certified e-waste recycling center.
III. Recycling E-waste is important because it helps conserve natural resources and reduces pollution.
Write a Python program to create the following DataFrame using a list of dictionaries.
No | Product | Price |
---|---|---|
0 | Laptop | 60000 |
1 | Desktop | 45000 |
2 | Monitor | 15000 |
3 | Tablet | 30000 |
import pandas as pd
d1 = {'Product': 'Laptop', 'Price': 60000}
d2 = {'Product': 'Desktop', 'Price': 45000}
d3 = {'Product': 'Monitor', 'Price': 15000}
d4 = {'Product': 'Tablet', 'Price': 30000}
data = [d1, d2, d3, d4]
df = pd.DataFrame(data)
print(df)
Product Price
0 Laptop 60000
1 Desktop 45000
2 Monitor 15000
3 Tablet 30000
Write a Python Program to create a Pandas Series as shown below using a dictionary. Note that the left column indicates the indices and the right column displays the data.
Russia | Moscow |
Hungary | Budapest |
Switzerland | Bern |
import pandas as pd
data = {'Russia':'Moscow','Hungary':'Budapest','Switzerland':'Bern'}
s = pd.Series(data)
print(s)
Russia Moscow
Hungary Budapest
Switzerland Bern
dtype: object
I. Write an SQL statement to create a table named STUDENTS, with the following specifications:
Column Name | Data Type | Key |
---|---|---|
StudentID | Numeric | Primary Key |
FirstName | Varchar(20) | |
LastName | Varchar(10) | |
DateOfBirth | Date | |
Percentage | Float(10, 2) |
II. Write SQL Query to insert the following data in the Students Table
1, Supriya, Singh, 2010-08-18, 75.5
Answer
I.
CREATE TABLE STUDENTS (
StudentID NUMERIC PRIMARY KEY,
FirstName VARCHAR(20),
LastName VARCHAR(10),
DateOfBirth DATE,
Percentage FLOAT(10,2)
);
II.
INSERT INTO STUDENTS (StudentID, FirstName, LastName,
DateOfBirth, Percentage) VALUES (1, 'Supriya', 'Singh', '2010-08-18',
75.5);
Consider the following tables:
Table 1:
EMPLOYEE which stores Employee ID (EMP_ID), Employee Name (EMP_NAME), Employee City (EMP_CITY)
Table 2:
PAYROLL which stores Employee ID (EMP_ID), Department (DEPARTMENT), Designation (DESIGNATION), and Salary (SALARY) for various employees.
Note: Attribute names are written within brackets.
Table: EMPLOYEE
EMP_ID | EMP_NAME | EMP_CITY |
---|---|---|
1 | ABHINAV | AGRA |
2 | KABIR | FARIDABAD |
3 | ESHA | NOIDA |
4 | PAUL | SEOUL |
5 | VICTORIA | LONDON |
Table: PAYROLL
EMP_ID | DEPARTMENT | DESIGNATION | SALARY |
---|---|---|---|
1 | SALES | MANAGER | 75000 |
2 | SALES | ASSOCIATE | 50000 |
3 | ENGINEERING | MANAGER | 95000 |
4 | ENGINEERING | ENGINEER | 70000 |
5 | MARKETING | MANAGER | 65000 |
Write appropriate SQL queries for the following:
I. Display department-wise average Salary.
II. List all designations in the decreasing order of Salary.
III. Display employee name along with their corresponding departments.
Answer
I.
SELECT DEPARTMENT, AVG(SALARY)
FROM PAYROLL
GROUP BY DEPARTMENT;
II.
SELECT DESIGNATION
FROM PAYROLL
ORDER BY SALARY DESC;
III.
SELECT EMP_NAME, DEPARTMENT
FROM EMPLOYEE E, PAYROLL P
WHERE E.EMP_ID = P.EMP_ID;
Consider the following tables:
Table 1:
ATHLETE, which stores AthleteID, Name, Country. The table displays basic information of the athletes.
Table 2:
MEDALS, which stores AthleteID, Sport, and Medals. The table displays the number of medals won by each athlete in their respective sports.
Table: ATHLETE
AthleteID | Name | COUNTRY |
---|---|---|
101 | Arjun | INDIA |
102 | Priya | INDIA |
103 | Asif | UAE |
104 | Rozy | USA |
105 | David | DENMARK |
Table: MEDALS
AthleteID | Sport | Medals |
---|---|---|
101 | Swimming | 8 |
102 | Track | 3 |
103 | Gymnastics | 5 |
104 | Swimming | 2 |
105 | Track | 6 |
Write appropriate SQL queries for the following:
I. Display the sports-wise total number of medals won.
II. Display the names of all the Indian athletes in uppercase.
III. Display the athlete name along with their corresponding sports
Answer
I.
SELECT Sport, SUM(Medals)
FROM MEDALS
GROUP BY Sport;
II.
SELECT UPPER(Name)
FROM ATHLETE
WHERE Country = 'INDIA';
III.
SELECT Name, Sport
FROM ATHLETE A, MEDALS M
WHERE A.AthleteID= M.AthleteID;
During a practical exam, a student Ankita has to fill in the blanks in a Python program that generates a bar chart. This bar chart represents the number of books read by four students in one month.
Student Name | Books Read |
---|---|
Karan | 12 |
Lina | 9 |
Raj | 5 |
Simran | 3 |
Help Ankita to complete the code.
import _____ as plt #Statement-1
students = ['Karan', 'Lina', 'Raj', 'Simran']
books_read = [12, 9, 5, 3]
plt.bar( students, _____, label='Books Read') #Statement-2
plt.xlabel('Student Name')
plt._____('Books Read') #Statement-3
plt.legend()
plt.title('_____') #Statement-4
plt.show()
I. Write the suitable code for the import statement in the blank space in the line marked as Statement-1.
II. Refer to the graph shown above and fill in the blank in Statement-2 with suitable Python code.
III. Fill in the blank in Statement-3 with the name of the function to set the label on the y-axis.
IV. Refer the graph shown above and fill the blank in Statement-4 with suitable Chart Title.
Answer
I. matplotlib.pyplot
II. books_read
III. ylabel
IV. Number of Books Read by Students
Rahul, who works as a database designer, has developed a database for a bookshop. This database includes a table BOOK whose column (attribute) names are mentioned below:
BCODE: Shows the unique code for each book.
TITLE: Indicates the book’s title.
AUTHOR: Specifies the author’s name.
PRICE: Lists the cost of the book.
Table: BOOK
BCODE | TITLE | AUTHOR | PRICE |
---|---|---|---|
B001 | MIDNIGHT'S CHILDREN | SALMAN RUSHDIE | 500 |
B002 | THE GOD OF SMALL THINGS | ARUNDHATI ROY | 450 |
B003 | A SUITABLE BOY | VIKRAM SETH | 600 |
B004 | THE WHITE TIGER | ARAVIND ADIGA | 399 |
B005 | TRAIN TO PAKISTAN | KHUSHWANT SINGH | 350 |
I. Write SQL query to display book titles in lowercase.
II. Write SQL query to display the highest price among the books.
III. Write SQL query to display the number of characters in each book title.
IV. Write SQL query to display the Book Code and Price sorted by Price in descending order.
Answer
I.
SELECT LOWER(TITLE)
FROM BOOK;
II.
SELECT MAX(PRICE)
FROM BOOK;
III.
SELECT LENGTH(TITLE)
FROM BOOK;
IV.
SELECT BCODE, PRICE
FROM BOOK
ORDER BY PRICE DESC;
Dr. Kavita has created a database for a hospital's pharmacy. The database includes a table named MEDICINE whose column (attribute) names are mentioned below:
MID: Shows the unique code for each medicine.
MED_NAME: Specifies the medicine name.
SUPP_CITY: Specifies the city where the supplier is located.
STOCK: Indicates the quantity of medicine available.
DEL_DATE: Specifies the date when the medicine was delivered.
Table: MEDICINE
MID | MED_NAME | SUPP_CITY | STOCK | DEL_DATE |
---|---|---|---|---|
M01 | PARACETAMOL | MUMBAI | 200 | 2023-06-15 |
M02 | AMOXICILLIN | KOLKATA | 50 | 2023-03-21 |
M03 | COUGH SYRUP | BENGALURU | 120 | 2023-02-10 |
M04 | INSULIN | CHENNAI | 135 | 2023-01-25 |
M05 | IBUPROFEN | AHMEDABAD | 30 | 2023-04-05 |
Write the output of the following SQL Queries.
I. Select LENGTH(MED_NAME) from MEDICINE where STOCK > 100;
II. Select MED_NAME from MEDICINE where month(DEL_DATE) = 4;
III. Select MED_NAME from MEDICINE where STOCK between 120 and 200;
IV. Select max(DEL_DATE) from MEDICINE;
Answer
I.
+------------------+
| LENGTH(MED_NAME) |
+------------------+
| 11 |
| 11 |
| 7 |
+------------------+
II.
+-----------+
| MED_NAME |
+-----------+
| IBUPROFEN |
+-----------+
III.
+-------------+
| MED_NAME |
+-------------+
| PARACETAMOL |
| COUGH SYRUP |
| INSULIN |
+-------------+
IV.
+---------------+
| max(DEL_DATE) |
+---------------+
| 2023-06-15 |
+---------------+
ABC Pvt. Ltd., a multinational technology company, is looking to establish its Indian Head Office in Bengaluru, and a regional office branch in Lucknow. The Bengaluru head office will be organized into four departments: HR, FINANCE, TECHNICAL, AND SUPPORT. As a network engineer, you have to propose solutions for various queries listed from I to V.
The shortest distances between the departments/offices are as follows:
HR TO FINANCE | 65 M |
HR TO TECHNICAL | 80 M |
HR TO SUPPORT | 70 M |
FINANCE TO TECHNICAL | 60 M |
FINANCE TO SUPPORT | 75 M |
TECHNICAL TO SUPPORT | 50 M |
BENGALURU OFFICE TO LUCKNOW | 1900 KM |
The number of computers in each department/office is as follows:
HR | 175 |
FINANCE | 35 |
TECHNICAL | 50 |
SUPPORT | 15 |
LUCKNOW OFFICE | 40 |
I. Suggest the most suitable department in the Bengaluru Office Setup, to install the server. Also, give a reason to justify your suggested location.
II. Draw a suitable cable layout of wired network connectivity between the departments in the Bengaluru Office.
III. Which networking device would you suggest the company to purchase to interconnect all the computers within a department in Bengaluru Office?
IV. The company is considering establishing a network connection between its Bengaluru Head Office and Lucknow regional office. Which type of network—LAN, MAN, or WAN—will be created? Justify your answer.
V. The company plans to develop an interactive website that will enable its employees to monitor their performance after login. Would you recommend a static or dynamic website, and why?
Answer
I. The server should be installed in the HR department as it has the most number of computers.
II. Star topology
III. Switch/Hub should be purchased by the company to interconnect all the computers within a department in Bengaluru office.
IV. A WAN (Wide Area Network) will be created because the offices are located in different cities, with a distance of 1900 km between the Bengaluru Head Office and the Lucknow Regional Office.
V. A dynamic website is recommended because it can display performance data that varies for each employee.
Consider the DataFrame df shown below.
MovieID | Title | Year | Rating | |
---|---|---|---|---|
0 | 1 | LAGAAN | 2001 | 8.4 |
1 | 2 | TAARE ZAMEEN PAR | 2007 | 8.5 |
2 | 3 | 3 IDIOTS | 2009 | 8.4 |
3 | 4 | DANGAL | 2016 | 8.4 |
4 | 5 | ANDHADHUN | 2018 | 8.3 |
Write Python statements for the DataFrame df to:
I. Print the first two rows of the DataFrame df.
II. Display titles of all the movies.
III. Remove the column rating.
IV. Display the data of the 'Title' column from indexes 2 to 4 (both included)
V. Rename the column name 'Title' to 'Name'.
Answer
I. print(df.head(2))
II. print(df['Title'])
III. df = df.drop(‘Rating’, axis=1)
IV. print(df.loc[2:4,'Title'])
V. df.rename(columns={'Title':'Name'}, inplace=True)
Write suitable SQL query for the following:
I. To display the average score from the test_results column (attribute) in the Exams table.
II. To display the last three characters of the registration_number column (attribute) in the Vehicles table. (Note: The registration numbers are stored in the format DL-01-AV-1234)
III. To display the data from the column (attribute) username in the Users table, after eliminating any leading and trailing spaces.
IV. To display the maximum value in the salary column (attribute) of the Employees table.
V. To determine the count of rows in the Suppliers table.
Answer
I.
SELECT AVG(test_results)
FROM Exams;
II.
SELECT RIGHT(registration_number, 3)
FROM Vehicles;
III.
SELECT TRIM(username)
FROM Users;
IV.
SELECT MAX(salary)
FROM Employees;
V.
SELECT COUNT(*)
FROM Suppliers;
Write suitable SQL query for the following:
I. Round the value of pi (3.14159) to two decimal places.
II. Calculate the remainder when 125 is divided by 8.
III. Display the number of characters in the word 'NewDelhi'.
IV. Display the first 5 characters from the word 'Informatics Practices'.
V. Display details from 'email' column (attribute), in the 'Students' table, after removing any leading and trailing spaces.
Answer
I.
SELECT ROUND(3.14159, 2);
II.
SELECT MOD(125, 8);
III.
SELECT LENGTH('NewDelhi');
IV.
SELECT LEFT('Informatics Practices', 5);
V.
SELECT TRIM(email)
FROM Students;