Important Python MCQs Test 4

The post is about the Python MCQS test with Answers. There are 20 multiple-choice questions from Pandas, Data Frame, Python data structures (such as lists, tuples, strings, and dictionaries, etc.), Python Editors, and Functions. Let us start with the Python MCQS Test.

Online Multiple-Choice Questions about Python Programming Language

1. In the pandas drop method we have a parameter called inplace, what is it used for?

 
 
 
 

2. What is the difference between the union and intersection of two sets in Python?

 
 
 
 

3. If you want to save data to a file, which of the following libraries should you use?

 
 
 
 

4. What Python data structure allows for the return of multiple items from a function?

 
 
 
 

5. How are the keys obtained as a list from a dictionary word_list?

 
 
 
 

6. A data professional is working with a pandas dataframe. They want to select a subset of rows and columns by index. What method can they use to do so?

 
 
 
 

7. How do you convert a set into a list?

 
 
 
 

8. Jupyter server supports only Python.

 
 

9. What datatype would the following variable have main_data=read.csv(“path/to/myfile.csv”)?

 
 
 
 

10. Which Python feature enables data professionals to define code once, and then use it many times without having to rewrite it?

 
 
 
 

11. Like Java, a function can be defined anywhere in a Python program.

 
 

12. Jupyter Notebook is an open-source ————– for creating and sharing documents containing live code, mathematical formulas, visualizations, and text.

 
 
 
 

13. How do you remove a key-value pair from a dictionary in Python?

 
 
 
 

14. What is the first element of “I Love Python”.split()?

 
 
 
 

15. Which of the following statements accurately describe Python lists?

 
 
 
 

16. What function(s) would print out the total missing data values for all columns of the dataframe main_data?

 
 
 
 

17. How is a definition stored in a dictionary, where ‘word’ is the key?

 
 
 
 

18. Why are functions important?

 
 
 
 

19. Which command will grab the last few rows of a dataframe?

 
 
 
 

20. Lines of code that begin with a ———— serve as comments and don’t get executed.

 
 
 
 

Python MCQs Test with Answers

Python MCQS Test with Answers
  • Like Java, a function can be defined anywhere in a Python program.
  • In the pandas drop method we have a parameter called inplace, what is it used for?
  • What is the difference between the union and intersection of two sets in Python?
  • How do you convert a set into a list?
  • How do you remove a key-value pair from a dictionary in Python?
  • How is a definition stored in a dictionary, where ‘word’ is the key?
  • How are the keys obtained as a list from a dictionary word_list?
  • What Python data structure allows for the return of multiple items from a function?
  • Jupyter server supports only Python.
  • What is the first element of “I Love Python”.split()?
  • Why are functions important?
  • Jupyter Notebook is an open-source ————– for creating and sharing documents containing live code, mathematical formulas, visualizations, and text.
  • Which Python feature enables data professionals to define code once, and then use it many times without having to rewrite it?
  • Which of the following statements accurately describe Python lists?
  • What datatype would the following variable have main_data=read.csv(“path/to/myfile.csv”)?
  • What function(s) would print out the total missing data values for all columns of the dataframe main_data?
  • Which command will grab the last few rows of a dataframe?
  • A data professional is working with a pandas dataframe. They want to select a subset of rows and columns by index. What method can they use to do so?
  • If you want to save data to a file, which of the following libraries should you use?
  • Lines of code that begin with a ———— serve as comments and don’t get executed.
Python MCQs Test with Answers
Frequently Asked Questions About R

https://itfeature.com, https://gmstat.com

Frequency Table in R: Factors Variable

Recall that in R language a factor is a variable that defines a partition into groups. A single factor variable can be used to create a simple frequency table in R, while a pair of factors can be used to define a two-way cross-classification (contingency or frequency distribution). For this purpose, the table() function allows to creation of frequency tables. The frequency table is calculated from equal length factors.

Frequency Table in R of Categorical/ Group/ Factor Variable

We will use the “mtcars” dataset. For the variable $gear$, let us create a frequency table using the table() function. The table() function will count the gear code for each entry in the data vector. For example,

attach(mtcars)

freq <- table(gear)
freq
frequency table using factor

The freq object will give a table of frequencies of each gear code in the sample. It is important to note that, the frequencies are ordered and labeled by the levels attribute of the factor.

Frequency Distribution of a Continuous Variable

One can also create a frequency distribution table for a continuous variable. Suppose from the mtcars data set, we are interested in creating a frequency table of $mpg$ variable. For this purpose, first, we need to define the cut points or bins to define the classes/groups of the frequency table. For example,

cut(mpg, 10+5*(0:5))

## Output
(10,15] (15,20] (20,25] (25,30] (30,35] 
      6      12       8       2       4 

The cut() function is used to split the continuous data vector into groups. The groups are defined by creating a sequence of values using 10+5*(0:5), that is

10+5*(0:5)

## Output
10 15 20 25 30 35

The cut() function, cuts and counts the occurrence of each observation of mpg regarding the cut points created using breaks = 10+5*(0:5). The frequency table will be

frequency table of a continuous variable

Creating Graph of Frequency Table

For the frequency table created above, one can easily create different graphical representations, such as pie charts and bar plots of the frequency table. For example,

freq<-table(cut(mpg, 10+5*(0:5)))
pie(freq)
hist(freq)
barplot(freq)
plot(freq)
Bar plot frequency table in R
bar plot in R language
pie chart in frequency table in R language

Note that: for a $k$ factor argument, the result is a $k$-way array of frequencies.

https://itfeature.com, https://gmstat.com

Types of Objects in R

R language operates on entities which are known as objects. There are various types of objects in R exists, such as vectors, matrices, factors, lists, data frames, functions, etc. In R, objects are classified into several types based on their structure and content.

Types of Objects in R

Matrices

Arrays or matrices are multi-dimensional generalizations of vectors. Matrices are vectors indexed by two or more indices and displayed specially. Matrices contain rows and columns of homogeneous elements. The class of matrices object is “matrix”. See more about matrices by following the matrices.

Factors

Factors are used to handle categorical data. Factor variables may contain two or more levels, used to define the group or category of the variable. See more about factors in detail by following factors.

Lists

Lists are a general form of vectors in which the various elements need not be of the same type, that is, lists may contain heterogeneous data. Lists are often vectors or lists themselves. Lists are a convenient way to get different results from statistical computation, as lists may contain different types of data objects. See more about lists by following the link Lists.

Data Frame

Data frame objects are similar to matrix object structures. Unlike matrix objects, the data frame objects may contain different types of objects, that is, heterogeneous data. Think of the data frame as “Data Matrices” with one row per observational unit but with (possibly) both numerical and categorical variables. Many experiments are best described by data frames, the treatments are categorical but the response (output) is numeric. For more details about the data frame, follow the link data frame.

Functions

Functions are themselves objects. In R Language, functions can be stored in the project’s workspace. Functions provide a quick, simple, and convenient way to extend the functionality and power of R. See more about functions and customization of functions, see Functions.

Examples of Different Types of Objects in R

# Scalar types
x <- 5        # Numeric (integer)
y <- 3.14159  # Numeric (double)
z <- "Hello"  # Character
b <- TRUE     # Logical

# Vector types
numbers <- c(1, 2, 3, 4)                  # Numeric vector
fruits <- c("apple", "banana", "orange")  # Character vector
bools <- c(TRUE, FALSE, TRUE)             # Logical vector

# Data frame
df <- data.frame(
  name = c("Ali", "Babar", "Usman"),
  age = c(25, 30, 28),
  city = c("Multan", "Lahore", "Karachi")
)

# Matrix
mat <- matrix(1:9, nrow = 3, ncol = 3)

# List
my_list <- list(
  numbers = numbers,
  fruits = fruits,
  df = df
)

# Factor
colors <- factor(c("red", "blue", "green", "red"))
Types of Objects in R Language

https://itfeature.com, https://gmstat.com