2 Flashcards

1
Q

Python: The lines within each block ( : ) must be

A

Indented e.g.
if var_1 == True:
print(“its true”)
break

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

Python: The function that places a value in the {} placeholder is

A

str.format(“value”) e.g. print(“my name is {}”.format(“Alen”))

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

Python: For a while loop, typing “while True:” will cause it to

A

loop forever, unless you add a “break” e.g.
if var_1 == 5
break

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

Python: For loops, the statement that will cause the loop to return to the top, without continuing the rest of the loop is called

A

continue

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

Python: To iterate/loop on every value in a list, use

A

for made_up_var in list_var:

print(made_up_var)

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

Python: Python stripts run in sequence so

A

Do not try to use a variable that only gets assigned later in the script

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

Python: For functions with arguments you must

A

Send in a value or else you will get an error

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

Python: An argument, with regards to functions, is

A

A value you pass into the function when you run it. e.g. my_function(argument1, argument2)

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

Python: You must tell a function what values to return by typing

A

return var_1, var_2

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

Python: functions start with the word

A

def

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

Python: function names should only use

A

lower case letters and underscores

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

Python: To add another if statement after the first one use

A

elif e.g.
elif var_1 == “SHOW”:
show_list()
continue

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

Python: After defining a function, to run it you must

A

call it e.g. my_function(argument)

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

Python: To import a python library, type

A

import name_of_library, into the python interpreter or top of script

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

Python: To call the “choice” method form the “random” library, type

A

random.choice()

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

Python: Can you create a new variable inside a function

A

Yes

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

Python: It’s recommended to do all the imports

A

at the beginning of the script

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

Python: It’s recommended to do the imports

A

at the beginning of the script

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

Python: You can imbed if and else commands

A

inside other if and else commands

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

Python: To get an automatic list of numbers starting from zero, type

A

list(range(10))

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

Python: You cannot reference variables outside of a function

A

From within the function. You must pass it in.

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

Python: To assign multiple variables simulaneously, type

A

var_1, var_2 = “Phil”, “Bill”

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

Python: Values on the right side of a variable always get

A

Evaluated first

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

Python: To insert a list into the middle of another list, type

A

list_1.insert(4, list_2)

The 4 denotes the index to insert at

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

Python: To generate a range of numbers, possibly for a loop, type

A

range(10)

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

Python: You can concatenate two lists together, without placing the second list within one index, by typing

A

[1, 2, 3] + [4, 5]

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

Python: Should you add a colon : after calling, not defining, a function?

A

No

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

Python: To add a line to a string, type

A

\n

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

Python: To do arithmetic on a variable in a shorter way, type

A

var += 2
var -= 2
var *= 2
var /= 2

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

Python: To remove all white space from the beginning and end of a string, type

A

“My string”.strip()

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

Python: Strings that are placed in a list must

A

have “ “ around them. e.g.

[“a”, “b”, “c”]

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

Python: Strings are

A

Immutable

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

Python: Lists are

A

Mutable

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

Python: To remove one item from a list by its index, type

A

del my_list[2]

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

Python: The del function does not work on

A

Strings, because they are immutable.

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

Python: To delete a list item by passing its value, type

A

my_list.remove(value)

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

Python: The remove() function only removes

A

The first instance of the passed value in the list

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

Python: When you use remove() on a value that does not exist it

A

throws an exception, so use within try/except

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

Python: To make a string lower case, type

A

lower(“STRING”) or “STRING”.lower()

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

Python: To capitalize the first letter of a string, type

A

capitalize(“string”) or string.capitalize()

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

Python: To remove a value from a list by its index and return it, type

A

my_list.pop(2)

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

Python: Inputs, input(), that are numbers should

A

Be converted to int() because input() is a string by default

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

Python: To return a portion of a list of string, type

A

my_list[3:4] or “my string”[1:6]

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

Python: To slice until the end of a string without knowing its length, type

A

my_string[1:len(my_string)]

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

Python: Slices, [:], do not alter a list, they

A

Return a copy of it

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

Python: To slice a list or string by returning steps that skip, type

A

my_list[1::2], Add an extra colon

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

Python: To return a string or list backwards using slice, type

A

my_string[::-1], make the skipping step a negative, and swap the start and end range [10:1:-1]

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

Python: Slices that start a range as a negative

A

Move the start point backwards through the end of the string or list and start slicing from there.

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

Python: Standard format for a function

A

my_list = list(range(3))

def first_4(my_iterable):
    four_arg = my_iterable[:4]
    return four_arg

first_4(my_list)

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

Python: Function checklist

A

The function def ends with :
The function is called somewhere
All of the arguments defined in the function are being passed in
All of the lines are indented the same
The variable referenced in the function are also assigned in the function
It ends with return

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

Python: Can you delete from the middle of a string?

A

No

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

Python: To delete a slice, type

A

del my_list[1:3]

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

Python: To replace a slice of a list with new items, type

A

my_list[4:7] = [“e”, “f”]

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

Python: The sections of the slice function are

A

[start:stop:step]

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

Python: To return the value associate with a key inside a dictionary, type

A

my_dict[“key_name”]

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

Python: To create a dictionary, type

A

my_dict = {“Key”: “Value”, “Key2”: “Value2”}

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

Python: You cannot return a key and value from a dictionary by its index because

A

The order changes and the keys and values are not attributed to an index

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

Python: Can you create a dictionary as a value of a key in another dictionary?

A

Yes

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

Python: Can you create lists within lists?

A

Yes

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

Python: The append() function is not recommended for concatenating 2 disparate lists because

A

It places the entirety of the appended list into the very last index of the initial string and does not set the values into individual indexes of the initial list.

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

Python: To return the value of a key in a dictionary that itself is the value of a key in a superceding dictionary, type

A

my_dict[“key_name”][“key_name2”]

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

Python: Returning a value from inside a function does not print it, it

A

Turns the calling function into that value.

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

Python: Functions must end with

A

return

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

Python: Before saving new code always check presence of

A

All necessary colons and indentations.

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

Python: The format for a “for loop” that checks for the presence of each of a lists items in a dictionary and then adds the items that are present to another list, is

A

present_in_list = []

for item in my_list:
if item in my_dict:
present_in_list.extend(item)

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

Python: elif requires

A

a True value test in order to run

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

Python: else does not require

A

a test because it runs whenever the test on “if” was False

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

Python: Returning a value from inside a function does not print it, it

A

Turns the value of the of the calling function into the returned value. If more than one value it returns as a tuple.

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

Python: The boolean values True and False must be

A

capitalized.

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

Python: To fill placeholders in a string using the format method without knowing which order to put the values, you can assign key names to values by typing

A

“My name is {name_key} and I am {age_key} years old”.format(age_key=”22”, name_key=”Alen”)

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

Python: To use the key name placeholders in the format method with the key values are stored in a dictionary, type

A

my_dict = {“state”: “California”, “name”: “Alen”}

“I am {name} and I live in {state}”.format(**my_dict)

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

Python: To create a new key for a dictionary, type

A

my_dict[“new_key_name”] = “value”

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

Python: To change the value of an existing dictionary key name, type

A

my_dict[“key_name”] = “new_value”

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

Python: To delete a key from a dictionary, type

A

del my_dict[“key_name”]

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

Python: To add and change values of multiple dict keys at once, type

A

my_dict.update({“job”: “Teacher”, “age”: “23”, “gender”: “male”})

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

Python: To create an empty dictionary, type

A

my_dict = {}

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

Pandas: To use pandas and be able to call it by a shorter name, type

A

import pandas as pd

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

Python: This returns a

def method():
    return var_1, var_2, var_3

method()

A

Tuple

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

Python: To return a tuple with the index and value from an iterable, type

A

enumerate(my_iterable)

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

Python: To unpack an enumerate()d tuple into a “for loop”, type

A

for tuple in enumerate(my_iterable):
print(“This is item number {} and it is a {}”.format(*tuple))

or

for index, item in enumerate(my_iterable):
print(“This is item number {} and it is a {}”.format(index, item))

or

for tuple in enumerate(my_iterable):
print(“This is item number {} and it is a {}”.format(tuple[1], tuple[2]))

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

Python: One asterisk in the format function

A

Unpacks a tuple

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

Python: To unpack an item tuple into a “for loop”, type

A

for key, value in my_iterable.items():

print(“This is the key {} and the value is {}”.format(key, value))

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

Python: You can create a tuple with either

A

placing a comma between 2 values or tuple()

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

Python: If a function returns three values you can either

A

Pack it into one variable or unpack it into three variable seperated by commas.

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

Python: To capitalize the first letter of every word, type

A

titlecase(“my_string”)

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

Python: To create a function that doesn’t need to be passed every parameter because there are defaults, type

A

def my_function(param_1=”A”, param_2=”B”, param_3=”Var”):

my_function()

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

IPYNB: To launch the IPython Notebook from the console, type

A

ipython notebook

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

Python: To run a python script, type into the console

A

python3 ~/myfolder/script.py

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

Python: When using a “for loop” on a dictionay, the “item” variable only takes on the value of

A

The key, not the key value

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

Python: To use a “for loop” on a dictionary and have the “item variable” iterate on the dictionaries values instead of the keys, type

A

for key in my_dict.values():
print(key)

or

for key in my_dict:
print(my_dict[key])

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

Python: To create a tuple, type

A

my_tuple = (1, 2, 3)

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

Python: For tuples, the parenthesis

A

Aren’t required. Only the commas are required.

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

Python: A tuple is an

A

Immutable list that can be packed and unpacked.

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

Python: You can turn a list into a tuple by typing

A

my_tuple = tuple(my_iterable)

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

Python: To return the value at a certain index in a tuple, type

A

my_tuple[2]

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

To enter the python interpreter in the cosole, type

A

python

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

Python script file names end with

A

.py

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

to exit the python Interpreter you type

A

exit()

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

To exit the help(word) function, type

A

q

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

To look up the attributes and methods of a class use

A

dir(nameofclass)

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

To assign a user input to a variable, type

A

var_1 = input(“Whatever you want the prompt to the user to be?”)

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

To invoke a newer language you installed in the terminal type

A

e.g. python3

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

To create a new text file, type

A

nano new_name.py

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

The placeholder for the str.format() method is

A

{} e.g. “I’m {}, and you are {}”.format(“Alen”, “Mike”)

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

The if and else function lines must end with

A

: (also try and except)

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

The methods that come after the if and else statements must

A

Be indented the exact same amount. The amount of spaces or tabs doesn’t matter.

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

A number with a decimal is called a

A

Float

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

A number without a decimal is called an

A

Integer

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

You can turn a string to an integer and a float with

A

int(“55”) float(“2.2”)

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

You can turn a float into an integer, and and integer into a float with

A

int(5.5) and float(5)

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

True + False will evaluate to

A

1 because True has a value of 1 and False has a value of 0

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

To check if a string is not in a variable string

A

if not “searchstring” in user_num:

print(“not here”)

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

To compare if two values are equal use

A

==

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

To try running something that might cause errors use

A

try:
1 / 0
except:
print(“script messed up”)

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

You can check if a string is in another string or list by typing

A

“g” in “dog”

This would return True

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

To get more info on a function, type

A

Into the interpreter, help(str.split)

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

To return the length of a list, type

A

len(my_list)

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

To return an item in a list by its index, type

A

my_list[3]

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

To change the value of one index in a list, type

A

my_list[3] = “new value”

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

To seperate all the letters of a string into seperate list items

A

list(“my string”)

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

To seperate the words in a string by white space, type

A

my_string.split()

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

To join a list with a delimiter, type

A

“_“.join(my_list)

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

The extend() method

A

Appends the second list onto the initial list and returns “None”. The second list remains the same value but the initial list will now contain the additional list indexes.

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

Console: Servers usually do not have a

A

GUI

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

Console: The “~” in the command line stands for

A

The home directory e.g. users/student/

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

Console: Usually the first word in the command line is

A

The username you are signed in as

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

Console: To list the files in your current directory, type

A

ls

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

Console: To list the files in the current directory with more detail, like permissions, type

A

ls -l

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

Console: To list all the files in the current directory including the hidden dot files, type

A

ls -a

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

Console: To clear the screen, type

A

clear

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

Console: to list the files in another directory, type

A

ls user/student/folder/

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

Console: “Folders” is synonymous with

A

Directories

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

Console: To see your current directory, type

A

pwd

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

Console: The home directory (“~”) usually contains the folders

A

My Documents, Pictures, etc.

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

Console: To change current directory, type

A

cd ~/myfolder/ or cd users/student/myfolder

136
Q

Console: To move up one directory, type

A

..

137
Q

Console: To see a previous command you typed, press

A

^ arrow

138
Q

Console: To view the contents of a text file, type

A

less ~/myfolder/file.txt or cat ~/myfolder/file.txt

139
Q

Console: To exit the “less” program, type

A

q

140
Q

Console: To concatenate two disparate files, type

A

cat ~/myfolder/file.txt ~/myfolder/file2.txt

141
Q

Console: To edit a text file, type

A

nano ~/myfolder/file.txt

142
Q

Console: To use the menu at the bottom on nano you must hold

A

control

143
Q

Console: To save in nano you must

A

ctrl x (exit) and then Y (yes) to the save prompt

144
Q

Console: To Save As in nano you must

A

ctrl x (exit) and then Y (yes) to the save prompt, then change the name it prompts

145
Q

Console: To rename a file or directory, type

A

mv hello.txt hi.txt or mv myfolder/ myfolder2/

146
Q

Console: To refer to current directory in a path type

A

.

147
Q

Console: When referencing directories always add

A

a slash at the end of the name

148
Q

Console: To move and rename a file simultaneously, type

A

mv python.txt /users/student/myfolder/newname.txt

149
Q

Console: To copy any file just type

A

cp myfolder/python.txt otherfolder/pythoncopy.txt

150
Q

Console: To copy a directory with all of the files included in it to another location, type

A

cp -r ~/myfolder/ ~/myfolder2/

151
Q

Console: To remove a file or an empty directory, use

A

rm myfolder/python.txt

152
Q

Console: Be careful since there is no undo for

A

rm

153
Q

Console: To use rm on a directory with files inside it, type

A

rm -r ~/myfolder/

154
Q

Console: To create a directory, type

A

mkdir name_of_directory/

155
Q

Console: To make a nested directory, type

A

mkdir -p documents/myfolder/pictures/

156
Q

Console: The permissions in ls -l are ordered by

A

Creator, Group, Public

157
Q

Python: Are tuples associated with an index?

A

Yes

158
Q

Pandas: To give a name to a Series, type

A

my_series.name=”Name of My Series”

159
Q

Pandas: To give a name to an index, type

A

my_series.index.name=”Name of My Index”

160
Q

Math: The mean is also called the

A

Average

161
Q

Math: The mode is

A

The number in a sequence that occurs most frequently

162
Q

Math: The median is

A

The number that is in the middle of the sequence if you put them all in order.

163
Q

Math: If you are attempting to find the median for a sequence has two numbers in the middle, you must

A

Find the mean for the two middle numbers

164
Q

Pandas: The data in a Series is

A

Homogeneous. If you change one values from an Int to a float they all become float.

165
Q

Pandas: If you use a dictionary as the data for a Series, it will

A

Automatically use the keys as the index and the values as the data.

166
Q

Pandas: A Series is an

A

Ordered key-value store

167
Q

Pandas: To multiply all the values in a Series, type

A

my_series * 2

168
Q

Pandas: To return a slice of a Series by the label, type

A

my_series[“Thur”:”Sat”]

169
Q

Pandas: To return a slice of a Series by the position, type

A

my_series[1:5]

170
Q

Pandas: To return one value in a Series based on it’s index, type

A

my_series[4]

171
Q

Pandas: To set the value of one index in a Series, type

A

my_series[3] =188

172
Q

Pandas: To return the median of a Series, type

A

my_series.median()

173
Q

Pandas: To return the max of a Series, type

A

my_series.max()

174
Q

Pandas: To change the values in a Series to the cumulative sum, type

A

my_series.cumsum()

175
Q

Pandas: To return the values of a series enumerated, type

A

for idx, value in enumerate(my_series):
print(idx, value)
Note: The reverse doesn’t work.

176
Q

Pandas: To check if a key is in a series, type

A

“Tue” in my_series

Would return true or false

177
Q

Pandas: To retrieve a Series value using a key or index, type

A

my_series[“Tue”]

178
Q

Pandas: To set a value by the key in a Series, type

A

my_series[“Wed”] =22

179
Q

Pandas: To loop over a Series or dictionary and return keys and values, type

A

for key, value in my_series.iteritems():

print(key, value)

180
Q

Python: When using my_list[4] to return a value, the square brackets contents can be

A

Anything that evaluates to a number. e.g. True, False

181
Q

Python: To return the position of a string inside another string, type

A

“Look in my string for the position”.find(“my string”)

182
Q

Python: If the find() method cannot find the string inside the main string, it returns

A

-1

183
Q

Python: The find() method only returns the position of

A

The first occurrence of the value you look for.

184
Q

Python: You can make the find() method start searching only after a set position by typing

A

“Look in my string for the position”.find(“my string”, 4)

185
Q

Console: When writing a file or directory path, always start the path with

A

A slash

186
Q

Python: To do exponentiation, type

A

2 ** 10

187
Q

Python: To create a while loop function, type

A
def while_function:
    i = 0
    while i
188
Q

Python: To return the index of an item in a list by its value, type

A

my_list.index(“list_item”)

Note: If the item is not present, this returns an error.

189
Q

Python: For value tests (like in while, if), an empty list and a not empty evaluate to

A

Empty: False

Not Empty: True

190
Q

Internet: A network is a

A

Group of entities that can communicate even though they are not all directly connected.

191
Q

Internet: Latency is

A

The time it takes for a message to go from source to destination.

192
Q

Internet: Bandwidth is

A

The amount of information that can be transmitted per unit time.

193
Q

IPYNB: To exit the ipython notebook from the console, type

A

control C, Y, Enter

194
Q

Console: To see the route a site takes in the network to get to you and the time, type

A

traceroute www.google.com

195
Q

Python: To time the execution of a function, type

A

import time

def time_execution():
    start = time.clock()
    eval("25 * 25")
    stop = time.clock()
    execution = stop - start
    return execution
196
Q

Python: Another way to execute the evaluation of code is

A

eval(2 * 2)

197
Q

Math: Modulo (%) is the

A

Remainder after dividing. e.g 5 % 2 = 1

198
Q

Python: To return a number associated with a single letter, type

A

ord(“A”)

199
Q

Python: To return a letter associated with a single number, type

A

chr(114)

200
Q

Pandas: A pandas DataFrame is

A

A spreadsheet with row and column labels.

201
Q

Pandas: A DataFrames data in a column is

A

Homogeneous

202
Q

Pandas: A DataFrames data can

A

Be any type

203
Q

Pandas: To create a DataFrame, type

A

my_data_dict = {“Tokyo”: [23, 43, 12, 65], “London”: [3, 4, 27, 55], “Date”: [1/20, 1/21, 1/22, 1/23]}

pandas.DataFrame(my_data_dict)

204
Q

Pandas: Every key-value list in the data dictionary going into a DataFrame must

A

Be the same length.

205
Q

Pandas: To return one column in a DataFrame (as a Series), type

A

df[“column name”] or

df.column_name

206
Q

Pandas: The data type for the return of one column in a DataFrame is

A

a Series

207
Q

Pandas: To set a DataFrame column to be the index, type

A

df.set_index(“column name”)

Note: Must use quotes.

208
Q

Pandas: To return only that last n rows of a DataFrame, type

A

my_dataframe.tail(10)

209
Q

Pandas: To return all unique values from a column along with their frequency, type

A

my_dataframe[“Column Name”].value_counts() or

my_dataframe.Column.value_counts()

210
Q

Pandas: To create a new column that totals others, type

A

df[“total”] = df[“Column1”] + df[“Column2”] + df[“Column3”]

211
Q

Plarium: The Tracker counts the ROI up until

A

The current moment for all the regs within the chosen time period.

212
Q

Plarium: The Payments ROI Comparison tool counts ROI until

A

The end date that you set at midnight.

213
Q

Plarium: For the end of month campaigns report

A

Use the Payments ROI Comparison tool.

214
Q

Pandas: To use value_counts(), you must use it on

A

A column Series

215
Q

Pandas: When importing a csv, you do not need to type

A

DataFrame

216
Q

Pandas: To sort a DataFrame by the index, type

A

df.sort_index()

217
Q

Pandas: To sort the columns of a DataFrame, type

A

df.sort_index(axis=1)

218
Q

Pandas: When referring to a column make sure to

A

Spell it perfectly and see if it needs quotes.

219
Q

Python: To open a browser automatically to a certain site from python, type

A

import webbrowser

webbrowser. get(‘firefox’)
webbrowser. open(“http://www.google.com”)

220
Q

Pandas: To sort a DataFrame by a column’s values, type

A

df.sort_index(ascending=False, by=[“Converted clicks”])

221
Q

Pandas: To sort a DataFrame by a two column’s values, type

A

df.sort_index(ascending=[False,True], by=[“Converted clicks”, “Avg. position”])

222
Q

Pandas: The order method returns a

A

Series

223
Q

Pandas: To sort a DataFrame you must use the

A

sort_index() method

224
Q

Chrome: To open last closed tab, type

A

Ctrl, Shift, T

225
Q

Python: Before calling new variables, make sure to

A

Initialize them.

eg. my_var = 0

226
Q

Pandas: The groupby object is not a

A

DataFrame. It is a dictionary where each unique value is a key and the value is the dataframe that has that value attributed.

227
Q

Python: The print function must use

A

Parentheses

228
Q

Pandas: The groupby() function

A

Splits the DataFrame into separate dataframe objects for every unique value in the passed in column.

229
Q

Pandas: A groupby object is dict like because (2 reasons)

A
  1. The unique column values are keys and the rest of the values are key values.
  2. It is iterable.
230
Q

Pandas: To create an empty DataFrame, type

A

df = pandas.DataFrame()

231
Q

Numpy: To invoke pylab, type

A

%pylab inline

232
Q

Pandas: To create a date range, type

A

days = pandas.date_range(“2014-01-01”, “2014-02-28”, freq = “d”)

233
Q

Pandas: To slice out a small range of the rows and columns, type

A

df.ix[2:45, “Madrid”:”Boston”]

234
Q

Pandas: To slice out specific rows and specific columns, type

A

df.ix[[5, 22, 31] , [“Madrid”,”Boston”,”Shanghai”]]

235
Q

Pandas: To slice out specific rows and all columns, type

A

df.ix[[5, 22, 31] , : ]

236
Q

Pandas: To slice out all rows and a range of columns, type

A

df.ix[ : , [“Madrid”:”Boston”]]

237
Q

Pandas: To transpose the columns and rows of a DataFrame, type

A

new_df = df.T

238
Q

Pandas: To look at just a few of the columns in a DataFrame, type

A

new_df = df[[“Bangladesh, “India”, “Uganda”]]

239
Q

Time: To make a python script wait for a certain time, type

A

import time

time.sleep(60)

240
Q

Console: To see the running processes, type

A

top -o cpu

241
Q

Console: To exit the “top” , type

A

q

242
Q

Pandas: When writing a path starting with the home directory, you must

A

Begin it with a slash.

243
Q

Pandas: Pandas automatically removes any excess

A

Blank rows and column from the CSV.

244
Q

Pandas: To check the number of rows in your DataFrame, type

A

len(df.index)

245
Q

Pandas: To change one column name, type

A

df = df.rename(columns = {“old_name”:

“new_name”})

246
Q

Pandas: To set a default maximum number of rows to display, type

A

pandas.set_option(“display.max_rows”, 10)

247
Q

Pandas: In order for df.to_csv(“”) to work, df must be

A

a DataFrame or a Series

248
Q

Pandas: In order to filter in pandas you must first create a

A

mask

249
Q

Pandas: To apply your mask to your df (filter for), type

A

df[mask]

250
Q

Pandas: To apply the inverse of your mask (filter out), type

A

df[numpy.invert(mask)]

Note: Must import numpy for this.

251
Q

Pandas: When you apply a boolean index (mask) to a df, it only returns the rows that the boolean index had as

A

True

252
Q

Pandas: To create a mask for one criteria, type

A

df[“Ad group”]==”Banner” or

df.Cost

253
Q

Pandas: To create a mask for multiple criteria, type

A

mask = (df[“Ad group”]==”Banner”) & (df.Cost>200)

254
Q

Matplotlib: To plot a line graph based on two df columns, type

A

df.plot(x=”Campaign”, y=”Cost”)

255
Q

Pandas: To get stats on every df column at a glance, type

A

df.describe()

256
Q

Pandas: To get a stat (e.g. median) for one column, type

A

df[“Column Name”].median()

257
Q

Pandas: To create a groupby, type

A

df.groupby(“Column Name”)

258
Q

Pandas: To remove the first row of a df, type

A

df = df.drop(df.index[:1])

259
Q

Pandas: To change the value of an exact coordinate (row and column), type

A

df.loc[5, “Cost”] = 10

260
Q

Pandas: To return the value of an exact coordinate (row and column), type

A

df.loc[24, “Campaign”]

261
Q

Python: To pass a function value to the third parameter, while leaving the others as their defaults, type

A

def my_function(param_1=”A”, param_2=”B”, param_3=”Var”):

my_function(param_3=”New Value!”)

262
Q

Python: Can you add an equation to the return line at the end of a function?

A

Yes

263
Q

Python: To apply a predefined function to every item in a list, in a short way, type

A

map(my_function, my_list)

264
Q

Pandas: To remove the last row of a df, type

A

df = df.drop(df.index[-1:])

265
Q

Pandas: To create a function meant to return a boolean index to be used as a filter(), type

A
new_list = []
def my_filter(a_list):
    for item in a_list:
        test = item > 5
        new_list.append(test)
    return new_list
266
Q

Pandas: To create a pivot table and choose the rows, columns, values, and presence of grand totals, type

A

table = pandas.pivot_table(df,index=[“Manager”,”Status”],columns=[“Product”],values=[“Quantity”,”Price”],aggfunc={“Quantity”:len,”Price”:[numpy.sum,numpy.mean]},fill_value=0)

267
Q

Pandas: To create a new column and make the values the return of a function acting on another column, type

A

df[“New Column”] = df[“Old Column”].apply(function_name)

Will be useful for data cleanup

268
Q

Python: To use a list comprehension to alter the items in a list, type

A

[float(item) for item in my_list]

269
Q

Pandas: To create a lambda function, type

A

lambda var_name: var_name**2

270
Q

Pandas: To create a list comprehension with an if statement, type

A

[item for item in my_list if item>5]

271
Q

Pandas: Can a lambda function take in multiple values?

A

Yes.

e.g. lambda var_name, var_name2: var_name*var_name2

272
Q

Pandas: Lambda functions automatically returns

A

The of the evaluation after the colon

273
Q

Numpy: The method that returns a standard deviation is

A

my_numpy_array.std()

274
Q

Pandas: To reverse the order of all the rows in a df, type

A

df.ix[::-1]

275
Q

Pandas: To combine two tables based on similar values in one column, like a lookup table, type

A

df.merge(df2, on=”Similar_Column_name”)

276
Q

Pandas: For a merge() to work the columns that the tables will merge on must be

A

Labeled the same.

277
Q

Pandas: Values (in the column that two tables are merging on) that do not match exactly on both tables when merging are

A

Removed

278
Q

Pandas: If a value in the merged on column of one table has a duplicate value that is also an exact match in the other table

A

The duplicate gets included in the merged table.

279
Q

Pandas: When the merged column has 2 duplicate exact match values on both tables, it

A

Combines the rows in every possible configurations, because it does not know which of the duplicates on one table matches with which of the duplicates of the other.

280
Q

Excel: To switch 2 rows or cells

A

Select the cell or row and press Ctrl x, then select the destination cell or row and press Ctrl, Shift, =

281
Q

Pandas: To replace an exact cell value in a specified entire column of a df with another value, type

A

df[“Column 1”] = df[“Column 1”].replace({“Fee”:”Fee Time”})

282
Q

Pandas: To strip all “$” signs from one column, type

A

df[“Column 1”] = df[“Column 1”].apply(lambda x: x.strip(“$”))

283
Q

Pandas: To strip any arrangement of a list of characters from the beginning of a string in a column, type

A

df[“Column 1”] = df[“Column 1”].map(lambda x: x.lstrip(“-+=&”))
or
df[“Column 1”] = df[“Column 1”].lstr.strip(“-+=
&”)

284
Q

Excel: To calculate correlation between 2 arrays, type

A

=correl(array_1, array_2)

285
Q

Numpy: To filter a numpy array with a boolean index, type

A

numpy_array[numpy_array > 5]

286
Q

Numpy: To use two boolean index filters on a numpy array, type

A

numpy_array[(numpy_array==5) | (numpy_array > 6)]

287
Q

Numpy: To create a numpy array, type

A

numpy.array([1,2,3])

288
Q

Numpy: To get the position of the max value in a numpy array, type

A

numpy_array.argmax()

289
Q

Numpy: To create a range in a numpy array, type

A

numpy.arange(20,30,1)

Start,stop,step.

290
Q

Numpy: Nan values in a numpy array

A

Screw up calculations and must be dealt with beforehand.

291
Q

Requests: To scrape all of the html content of a page into a variable, type

A

import requests

page = requests.get(“http://www.scrape.com”)

292
Q

Requests: To see all of the html scraped by requests in your variable, type

A

page.content

293
Q

BS4: To put scraped data into BS from the var used by requests, type

A

from bs4 import BeautifulSoup

soup_page = BeautifulSoup(page.content, “html.parser”)

294
Q

BS4: To print a BS content variable in a pretty way, type

A

print(soup_page.prettify())

295
Q

BS4: To return all of the content contained in a certain html tag, type

A

soup_page = BeautifulSoup(page.content)

soup_page.find_all(“a”)

296
Q

BS4: To return all the values of a certain parameter from a list of html tags, type

A

for item in soup_page.find_all(“a”):

print(item.get(“href”))

297
Q

BS4: To return all the anchor text for every link in a soup page, type

A

for item in soup_page.find_all(“a”)

print(item.text)

298
Q

Python: To return the value of a dictionary key using a method, type

A

my_dict.get(“Key name”)

299
Q

Requests: The requests library is a

A

site scraper

300
Q

BS4: The beautiful soup is an

A

html parser

301
Q

Pandas: To add new rows to a DataFrame, use

A

concat

302
Q

Pandas: To add new columns to a DataFrame that are a different length than the original and have pandas fill the the missing data with nan, rather than deleting any rows, type

A

df1.join(df2, how=’outer’)

303
Q

Pandas: To groupby by two columns, type

A

grouped = df.groupby([“Google Name”, “Adgroup”]).agg({“Regs”: numpy.sum, “Deposits Amount”: numpy.sum})

304
Q

Pandas: To turn a column value that pandas thinks is an int/float to a string, type

A

df[“Campaign”] = df[“Campaign”].apply(lambda x: str(x))

305
Q

Pandas: To turn a groupby into a flat table, type

A

grouped.reset_index()

306
Q

Pandas: To remove all rows with “VALUE!”, inside one column of a data frame, use

A

A filter.

307
Q

Pandas: To remove rows with duplicate values in a df column and keep the last one, type

A

df.drop_duplicates(subset=”Column name”, take_last=True)

308
Q

Pandas: To filter for df rows that contain certain values in a column, type

A

df[df[‘Column Name’].isin([3, 6])]

309
Q

Pandas: To create a filter mask with “or” criteria, type

A

(df[“Column 1”] >= 5) | (df[“Column 2”] > 45)

310
Q

Pandas: To create a groupby for multiple columns data, and aggregate one of the columns by two functions, type

A

df.groupby([“Campaign”, “Adgroup”]).agg({“Adgroup”: [numpy.size, numpy.mean]})

311
Q

Pandas: The apply function does not require your

A

function to iterate.

312
Q

Pandas: To return the row of a certain value in a column, type

A

df[“Column_name”][df[“Column name”] == “Value name”].index.tolist()[0]

313
Q

Pandas: To turn a list into a number, use

A

”“.join(“my_list”)

314
Q

BS4: The find_all(“a”) method returns

A

a List of all the “a” tags.

315
Q

Pandas: To use a text filter on a df, type

A

df[df[“Column name”].str.contains(“string”)]

316
Q

OS: To return the current directory automatically, type

A

import os

path = os.getcwd()

317
Q

BS4: To parse a site with potentially broken html, type

A

soup_page = BeautifulSoup(page, “html.parser”)

318
Q

BS4: To use .get(“href”) and then place return into a list, type

A

new_list = []
for item in soup_page.find_all(“a”, {“class”:”title may-blank “}:
new_list.extend([item.get(“href”)])

319
Q

BS4: When using soup_page.find_all(“a”, {“class”:”name”})

A

The parameters must be an exact match

320
Q

Selenium: To run a loop that will sometimes return errors, but you want it to continue, type

A
for item in site_list:
    try:
        my_browser.get(item)
    except:
        pass
321
Q

Python: To execute some code immediately after a for loop has iterated over every item, type

A

for item in range(1,10):
print(item)
else:
print(“finished”)

322
Q

CLI stands for

A

command line interface

323
Q

python: Python’s GIL is

A

a Global Interpreter Lock. A mechanism that prevents executions of multiple python bytecode instructions simultaneously.

324
Q

http: SSL stands for

A

secure sockets layer

325
Q

http: SSL is

A

an encrypted connection between server and client

326
Q

bash: To remove a directory type

A

rm -r directory_name

327
Q

python: When importing a file,

A

point to it from your current working direcory

328
Q

python: Do not name your python file

A

the same as a library name you are importing, otherwise it will import itself.

329
Q

python: To evaluate a string that is assigning a value to

A

exec(“var_name = 1”)

330
Q

python: var_name = 1 is not an expression, it is a

A

statement

331
Q

python: To return the first value in a list that matches a criteria, type

A

first(x for x in my_list if x == 10)

332
Q

pandas: To import mongodb into pandas, use

A

pymongo

333
Q

python: To sort a dict by key, type

A

sorted(my_dict.items(), key=lambda x: x)

334
Q

python: my_dict.items() returns

A

a list where each item is a tuple that contains the key and value

335
Q

python: To remove an df from RAM memory, type

A

del df
import gc
gc.collect()