1/64
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
F-string
print (f “I have this many {variable}.”)
String concatenation
print (“I understand how to + variable + fish at a specific temperature of + variable2 + “.” ”)
Combines strings with an operator like + (plus) , (comma) % (remainder)
if statements
allows you to make decisions on certain conditions through programming
if age >= 21:
print (“You can have a drink!”)
elif
else if; takes consideration of other decisions or numbers
if age == 21:
print (“You can have a drink!”)
elif age > 21:
print(“Oh yeah! You can definitely have a drink!”)
else
means that if all conditions were not met or not true; this considers all other factors that are not true
if age == 21:
print (“You can have a drink!”)
elif age > 21:
print (“Oh yeah! You can have a drink!”)
else:
print (“Have a glass of water.”)
+
addition
-
subtraction
*
multiplication
/
division
**
power
%
remainder
cast
when you take a function and cover it with another function outward
int(input(“What is your favorite number?”))
.upper()
make it upper case; CHANGE is PERMANENT
.lower()
CHANGE the name to lower case; no permanent
.title()
updates the name in proper form
.replace()
replaces values or update the values
.replace(“I”, ““)
.partition()
divides the strings into 3 separate parts based on a specific separator
name = “Franklin D. Roosevelt”
separateNames = name.replace()
output:
(“Franklin”, ““ “D. Roosevelt”)
.split()
splits a string into a list of strings after breaking the given string by a specified separator
name = "roseanne chaeyoung park”
separateName = name.split()
output
[“roseanne” “chaeyoung” “park”]
.strip()
strips unnecessary space
index
counts from zero to how many digits a character signifies
CHEESE = 0, 1, 2, 3, 4, 5 (in total would be 6 digits)
Tuples
Purpose: Collection of values
Special/Unique: cannot be modified; only read
Defined by: () —> parentheses
name_tuple = (“Jinsoul”, ““, “Kim”) —> index of 3
Loop
repeats the same action or sequence multiple times; requires an iterator/counter;
for each_name in name_tuple
print(each_name) - indented
print(“Stan Loona”) - indented
print(“Loop by Yves SOTY”)
List
Purpose: collection of values
Special: can be CHANGED
Defined: Squared Brackets []
.append()
Special to lists; adds to a list as a new value
.merge()
Given if there is another list to add to another —> list2.merge(list1)
.pop()
uses an index to remove something —> list1.pop(4) — pops the value holder of 4
.clear()
removes the list in its entirety
Sets
Purpose: collection of values/data
Unique: Does not allow for duplicates/all values have to be unique
Defined by: {} curly braces
.add()
Special to sets
adds another value to the set; but has to be a different value
.union()
two lists are asked to be combined; it does combine them and any duplicates are listed as 1
.intersection()
finds the values that are shared within both sets; join two sets but only includes common elements
.issubset()
the set is contained inside of another (mostly used in a if statement)
.issuperset()
contains another set in another (mostly use in a if statement)
Dictionaries
Purpose: A collection of values that are logically connected
Unique: DEFINED & MULTIPLE keys; each data point has a key/value pairing
Concept: Object-Oriented Programming
Function
A collection of “code” that can be “CALLED” multiple times from various points in our code
Parameter
passed in or returned out from a function
Argument
known or pre-defined parameter
PANDAs
Purpose: multidimensional table (2d)
series
one column of data; multiple series — creates a table
data frame
2 dimensional data (df)
import pandas as pd
is not necessary completely, but required if you want to use the features of PANDAs then you must do this
.Series()
makes a list of data into a series
df.head()
the first 5 rows are shown
df.tail()
the last 5 rows are shown
df.info()
when we want basic info about our df (how many rows, how many columns, what is the type of data)
pd.read_csv()
loads data directly into a dataframe
df.to_string()
outputs the df to a string
df.shape
how many rows and columns do we have in our df
.unique()
returns a list of all the unique values of columns
len(variable)
tells you how many in that list —> gives you a number
.isna()
how many rows in the columns have null values; returns a list of booleans
TRUE YES 1
FALSE NO 0
variable.sum()
counts how many in the list that we want to see that might have null values
.max()
gives the maximum value of a column
.min()
gives the minimum value of a column
.mean()
gives you the average of the column
.query()
looks through that section and gives you the specific row (subset) back to you either in another variable
columns/series need to be in backquotes
df.query(“ Starting Median Salary
` > 75000”)
df.describe()
looks at all the descriptive statistics of the df
df.drop
drops the row in its entirety but there is some caution either in updating it or removing it in its entirety which switches its space
df.drop(index = 256, inplace = True) —> keeps it in place and just updates it
df.drop(index = 256) —> removes it completely and restructures the df
pd.to_numeric
df['Starting Median Salary'] = pd.to_numeric(df['Starting Median Salary'], errors='coerce')
takes the entire section and forces (“coerces it”) into numeric values
df.loc[21, 'Starting Median Salary'] = None
df.loc[22, 'Starting Median Salary'] = ""
df.loc[22, 'Starting Median Salary'] = 42600
used for updating a location by providing its index and column name, to which the person would add the value to “update it”
df.to_csv('/drive/My Drive/testfile.csv')
to transfer the df into a csv file (comma separate value)
df['short_description'].replace(to_replace=r'^B',value='T', regex=True, inplace=True)
looks for patterns in data and completely updates with the regular expression value called “regex”