2 - The Basics Flashcards
What is required to run Python code?
A Python compiler, specifically the Spyder compiler included in the Anaconda software package.
How do you download Anaconda?
Go to the Spyder installation page and select the Anaconda link under Windows or MacOS X options.
What are the three main boxes displayed when you first open Spyder?
- 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.
What are the five kinds of actions focused on in Python coding?
- Using comments
- Importing packages
- Executing commands
- Saving output
- Getting data into Python.
What character is used to start a comment in Python?
#
True or False: Comments in Python are executed by the compiler.
False
What is the purpose of comments in Python code?
To help others understand the code better.
How do you execute a single line of code in Spyder?
Place the cursor on the line and press the run button or use the keyboard shortcut.
How do you execute multiple lines of code in Spyder?
Highlight the relevant lines and press the ‘Run selection or current line’ button or use the keyboard shortcut.
What is the purpose of importing packages in Python?
To perform complex data science tasks without writing the code from scratch.
Which two packages are commonly imported in Python for data science?
- pandas
- numpy.
What command is used to import the pandas package as pd?
import pandas as pd
What command is used to import the numpy package as np?
import numpy as np
Fill in the blank: To import specific commands from a package, use the format _____ from _____ import _____.
from [package_name] import [command_name]
What is the structure of the command to get a data set into Python?
your_name_for_the_data_set = pd.read_csv(‘the_path_to_the_file’)
What does the command pd.read_csv() do?
It imports a CSV file into a pandas DataFrame.
What is the syntax for saving output in Python?
your_name_for_the_output = the_command_that_generated_the_output
What is the purpose of saving output in Python?
To use the output in later lines of code.
What Python command is used to create a contingency table?
pd.crosstab()
How do you access a specific record in a pandas DataFrame?
Use the .loc attribute followed by the record index.
How do you view the first record in a DataFrame named bank_train?
bank_train.loc[0]
How do you access multiple records in a DataFrame?
Use the .loc attribute and list the record indices.
If you want to see the first 10 rows of a DataFrame, what is the syntax?
bank_train[0:10]
How do you access a single variable in a DataFrame?
Use bank_train[‘variable_name’]