2 - The Basics Flashcards

1
Q

What is required to run Python code?

A

A Python compiler, specifically the Spyder compiler included in the Anaconda software package.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you download Anaconda?

A

Go to the Spyder installation page and select the Anaconda link under Windows or MacOS X options.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three main boxes displayed when you first open Spyder?

A
  • Left-hand box: where you write Python code
  • Top-right box: lists data sets and items created by Python code
  • Bottom-right box: displays output and error messages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the five kinds of actions focused on in Python coding?

A
  • Using comments
  • Importing packages
  • Executing commands
  • Saving output
  • Getting data into Python.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What character is used to start a comment in Python?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

True or False: Comments in Python are executed by the compiler.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the purpose of comments in Python code?

A

To help others understand the code better.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you execute a single line of code in Spyder?

A

Place the cursor on the line and press the run button or use the keyboard shortcut.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you execute multiple lines of code in Spyder?

A

Highlight the relevant lines and press the ‘Run selection or current line’ button or use the keyboard shortcut.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of importing packages in Python?

A

To perform complex data science tasks without writing the code from scratch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which two packages are commonly imported in Python for data science?

A
  • pandas
  • numpy.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What command is used to import the pandas package as pd?

A

import pandas as pd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What command is used to import the numpy package as np?

A

import numpy as np

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Fill in the blank: To import specific commands from a package, use the format _____ from _____ import _____.

A

from [package_name] import [command_name]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the structure of the command to get a data set into Python?

A

your_name_for_the_data_set = pd.read_csv(‘the_path_to_the_file’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does the command pd.read_csv() do?

A

It imports a CSV file into a pandas DataFrame.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is the syntax for saving output in Python?

A

your_name_for_the_output = the_command_that_generated_the_output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the purpose of saving output in Python?

A

To use the output in later lines of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What Python command is used to create a contingency table?

A

pd.crosstab()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How do you access a specific record in a pandas DataFrame?

A

Use the .loc attribute followed by the record index.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How do you view the first record in a DataFrame named bank_train?

A

bank_train.loc[0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you access multiple records in a DataFrame?

A

Use the .loc attribute and list the record indices.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

If you want to see the first 10 rows of a DataFrame, what is the syntax?

A

bank_train[0:10]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How do you access a single variable in a DataFrame?

A

Use bank_train[‘variable_name’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do you access multiple variables in a DataFrame?
Use bank_train[['var1', 'var2']]
26
What must you do to set up graphics in Spyder for better display?
Change the graphics settings to 'Automatic' in Preferences.
27
What is the first step to change graphics settings in Spyder?
Click on Tools in the menu bar, then select Preferences.
28
What is the first step to set up graphics options in Spyder?
Click on Tools in the menu bar, then select Preferences
29
In Spyder, where do you find the Graphics tab to change settings?
In the Preferences window, on the top of the right‐hand side
30
What should you select under Graphics backend to enable graphical output?
Choose Automatic from the Backend drop‐down menu
31
What must you do after changing the graphics options in Spyder?
Close Spyder and reopen it for the new settings to take effect
32
True or False: Changing the graphics backend will open graphical output in the same window.
False
33
What is the main purpose of the Configure subplots button in the graphics output window?
To change the margins of the plot
34
What is the first action required to download R?
Go to the R installation page and choose a mirror
35
How do you open a new R script in RStudio?
Click on File > New File > R Script
36
What is located in the top-left box of the RStudio interface?
Where you will type your R code
37
What does the bottom-right box in RStudio primarily display?
Many tabs, including the 'Plots' tab for graphical output
38
What symbol is used to start a comment in R code?
#
39
How do you execute a single line of R code in RStudio?
Click the Run button or use the keyboard shortcut
40
What are the two steps to make an R package available for use?
* Downloading the package * Opening the package
41
Fill in the blank: To download a package in R, you use the command _______.
install.packages()
42
What command do you use to open an R package after it's been downloaded?
library()
43
What is the easiest method to get a data set into R?
Using the 'Import Dataset' button in the RStudio Environment tab
44
What should be selected in the Import Dataset window to indicate the presence of column headers?
The 'Yes' button for 'Heading'
45
What is the general form to rename a data set in R?
object_name <- object_to_be_saved
46
What command is used to read a CSV file into R?
read.csv()
47
How do you create a contingency table in R?
Use the table() function
48
What notation is used to access a specific record in a data set in R?
Bracket notation: data_set_name[ rows of interest , columns of interest ]
49
What does the command bank_train[1, ] return?
The first record in the bank_train data set
50
How do you access multiple records, for example, the first, third, and fourth records in R?
bank_train[c(1,3,4), ]
51
How can you access specific variables in a data set in R?
Use bracket notation for columns: data_set_name[, c(column_indices)]
52
What is the result of the command bank_train[, c(1, 3)]?
It returns the first and third variables from the bank_train data set
53
What are the first and third variables in the data set?
age and marital
54
How do you access specific variables in a data frame in R?
Use the syntax bank_train[, c(1, 3)]
55
How can you access the age variable from the bank_train data set?
bank_train$age
56
What property do data frames have that allows identifying variables of interest?
You can use a dollar sign ($)
57
What programming languages are covered in this book?
Python and R
58
What is the purpose of comments in code?
To provide explanations or notes without affecting output
59
What character begins a comment in Python?
#
60
What is the use of the 'as' keyword when importing Python packages?
To rename the imported package
61
How do you save output generated by Python code?
Use assignment to a variable
62
How do you save output generated by R code?
Assign output to a variable
63
Why is it important to specify if a data set has column headings?
To ensure proper data interpretation and manipulation
64
What are two ways to get a data set into R?
* Using read.csv() * Using read.table()
65
What is contained in the bottom-right window of a programming environment?
Output or results of executed code
66
What is the output of executing a comment in R?
No output is generated
67
What packages should be imported for Python in the exercises?
* pandas * numpy
68
What package should be imported for R in the exercises?
ggplot2
69
What is the name given to the imported bank_marketing_training data set?
bank_train
70
What is a contingency table?
A table used to display the frequency distribution of variables
71
What is the name of the saved output for the contingency table in Python?
crosstab_01
72
What is the name of the saved output for the contingency table in R?
t1
73
How do you save the first nine records of the bank_train data set?
Assign them to a new data frame
74
How do you save the age and marital records of the bank_train data set?
Assign them to a new data frame
75
How do you save the first three records of the age and marital variables?
Assign them to a new data frame
76
What should be done when importing the adult_ch3_training data set?
Use the 'Heading: Yes' setting
77
What command should be imported for Python related to decision trees?
DecisionTreeClassifier from sklearn.tree
78
What package should be imported for R related to decision trees?
rpart
79
What is the name given to the contingency table of workclass and sex?
table01
80
What is the name given to the contingency table of sex and marital status?
table02
81
What records should be displayed to analyze sex and workclass?
The first record
82
What records should be displayed to analyze sex and marital status?
Records 6–10
83
What is the name of the new data set for married individuals?
adultMarried
84
What is the name of the new data set for individuals older than 40?
adultOver40