Showing posts with label tuple. Show all posts
Showing posts with label tuple. Show all posts

Wednesday, April 20, 2022

Data Structures in Data Science using Python


What is a Data Structure?

To make data manipulation and other data operations more efficient, a data structure is used to store data in an ordered manner.


Types of Data Structures:

1. Vector- It is a homogeneous data structure and one of the most basic data structures. It only contains components of the same data type, in other words. Numeric, integer, character, complex, and logical data types are possible.

How to Create a Vector in Python:
In Python, use the np.array( ) function to create a vector.
# Vector as row
vec_row = np.array([1, 2, 3])
vector_row
#Vector as column
vec_column = np.array([[1],
[2],
[3]])
vector_column


2. Matrix- A matrix is a two-dimensional data structure with a homogeneous structure. This signifies that only items of the same data type are accepted. When elements of various data types are transmitted, coercion occurs.

How to Create a Matrix in Python:
Python uses the np.mat( ) function to create a matrix.
matrix = np.mat([[1, 2],
[1, 2],
[1, 2]])
matrix

 
3. Array- They're data structures with several dimensions. Data is kept in an array in the form of matrices, rows, and columns. The matrix elements can be accessed using the matrix level, row index, and column index.

How to Create an Array in Python:
In Python, use square brackets to create arrays.
cars = ["Tata", "Maruti", "Mahindra"]
cars

 
4. Series- It's only available in Python, especially when using the Pandas package. It's a one-dimensional labeled array that can hold any data (integer, string, float, python objects, etc.). The axis labels are referred to as the 'index'.

How to Create a Series in Python:
first create an array using the array( ) function. Then feed the array as an input into the series using the Series( ) function. a = np.array(['H', 'a', 'n', 'u', 'm', 'a', 'n'])
s = pd.Series(a)
s

 
5. Data Frame- A data frame is a two-dimensional array with a table-like appearance. Each row includes one set of values from each column, and each column contains one set of values. A data frame can contain numeric, factor, or character data. The number of data items in each column should be the same.

How to Create a Data Frame in Python: A data frame is a collection of series in Python. The data-frame is created with the pandas package. To make the data frame, use the DataFrame function.
#Dataframe
cars = pd.read_csv("C:/cars.csv")
df = pd.DataFrame(cars)
df


6. List- Lists can contain elements of various sorts, such as numbers, texts, vectors, and other lists. A matrix or a function can be one of the members of a list. It is an ordered and changeable collection (it can be changed). It may have duplicate values.

How to Create a List in Python:
Creating a variable, opening a square bracket, and inputting the desired values are all it takes.
n = ["Red", "Radha", (21,32,11), True, 51.23]
n


7. Dictionary- It's also known as a hash map, and it accepts arbitrary keys and values. Numbers, numeric vectors, strings, and string vectors can all be used as keys. It's a changeable, indexed, and unordered database. It can't have any duplicate values in it.

How to Create a Dictionary in Python:
Open a curly bracket, enter the values, and specify the key.
dict = {1: [1, 2, 3, 4], 'Name': 'Krishna'}
dict


8. Tuple- Python is the only language that has it. It is made up of organized and unchangeable elements. A tuple can contain any number of items, including various types (integer, float, list, string, etc.). There are duplicate members in this group.

How to Create a Tuple in Python: Make a variable, open parenthesis, and fill in the values.
tuple1 = ("Banana",1, False)
print(tuple1)


References:
1. https://medium.com/@vinitasilaparasetty/data-structures-in-data-science-4f47d9c4ab94

Wednesday, September 23, 2020

Database Systems MCQ

 Q.1 In the relational modes, cardinality is termed as:

(A) Number of tuples. 

(B) Number of attributes.

(C) Number of tables. 

(D) Number of constraints.

Ans: A


Q.2 Relational calculus is a

(A) Procedural language. 

(B) Non- Procedural language.

(C) Data definition language. 

(D) High level language.

Ans: B


Q.3 The view of total database content is

(A) Conceptual view. 

(B) Internal view.

(C) External view. 

(D) Physical View.

Ans: A


Q.4 Cartesian product in relational algebra is

(A) a Unary operator. 

(B) a Binary operator.

(C) a Ternary operator. 

(D) not defined.

Ans: B Cartesian product in relational algebra is a binary operator. (It requires two operands. e.g., PXQ)


Q.5 DML is provided for

(A) Description of logical structure of database.

(B) Addition of new structures in the database system.

(C) Manipulation & processing of database.

(D) Definition of physical structure of database system.

Ans: C DML is provided for manipulation & processing of database. (Data stored in the database is processed or manipulated using data manipulation language commands as its name)


Q.6 ‘AS’ clause is used in SQL for

(A) Selection operation. 

(B) Rename operation.

(C) Join operation. 

(D) Projection operation.

Ans: B ‘AS’ clause is used in SQL for rename operation. (e.g., SELECT ENO AS EMPLOYEE_NO FROM EMP)


Q.7 ODBC stands for

(A) Object Database Connectivity.

(B) Oral Database Connectivity.

(C) Oracle Database Connectivity.

(D) Open Database Connectivity.

Ans: D


Q.8 Architecture of the database can be viewed as

(A) two levels. 

(B) four levels.

(C) three levels. 

(D) one level.

Ans: C


Q.9 In a relational model, relations are termed as

(A) Tuples. 

(B) Attributes

(C) Tables. 

(D) Rows.

Ans:


Q.10 The database schema is written in

(A) HLL 

(B) DML

(C) DDL 

(D) DCL

Ans: C


Q.11 In the architecture of a database system external level is the

(A) physical level. 

(B) logical level.

(C) conceptual level 

(D) view level.

Ans: D


Q.12 An entity set that does not have sufficient attributes to form a primary key is a

(A) strong entity set. 

(B) weak entity set.

(C) simple entity set. 

(D) primary entity set.

Ans: B


Q.13 In a Hierarchical model records are organized as

(A) Graph. 

(B) List.

(C) Links. 

(D) Tree.

Ans: D


Q.14 In an E-R diagram attributes are represented by

(A) rectangle. 

(B) square.

(C) ellipse. 

(D) triangle.

Ans: C


Q.15 In case of entity integrity, the primary key may be

(A) not Null 

(B) Null

(C) both Null & not Null. 

(D) any value.

Ans: A


Q.16 In tuple relational calculus P1 -> P2 is equivalent to

(A) ¬P1vP2 

(B) P1vP2

(C) P1^P2 

(D) P1^¬P2

Ans: A In tuple relational calculus P1 -> P2 is equivalent to ¬P1vP2. (The logical implication expression A->B, meaning if A then B,is equivalent to ¬AvB)


Q.17 The language used in application programs to request data from the DBMS is referred to as the

(A) DML 

(B) DDL

(C) VDL 

(D) SDL

Ans: A


Q.18 A logical schema

(A) is the entire database.

(B) is a standard way of organizing information into accessible parts.

(C) describes how data is actually stored on disk.

(D) both (A) and (C)

Ans: A


Q.19 Related fields in a database are grouped to form a

(A) data file. 

(B) data record.

(C) menu. 

(D) bank.

Ans: B Related data fields in a database are grouped to form a data record. (A record is a collection of related fields)


Q.20 The database environment has all of the following components except:

(A) users. 

(B) separate files.

(C) database. 

(D) database administrator.

Ans: A


Q.21 The language which has recently become the defacto standard for interfacing application programs with relational database system is

(A) Oracle. 

(B) SQL.

(C) DBase. 

(D) 4GL.

Ans: B


Q.22 The way a particular application views the data from the database that the application uses is a

(A) module. 

(B) relational model.

(C) schema. 

(D) sub schema.

Ans: D


Q.23 In an E-R diagram an entity set is represent by a

(A) rectangle. 

(B) ellipse.

(C) diamond box. 

(D) circle.

Ans: A


Q.24 A report generator is used to

(A) update files. 

(B) print files on paper.

(C) data entry. 

(D) delete files.

Ans: B

Search Aptipedia