notebooks Flashcards
class
can be thought of as a type. it determines what you can do with a variable and what operators you can use with this class. it will define what all operators mean when applied to objects.
object
an instance of a class. every variable in your program is in fact an object.
type() function
tells us about what is the class of this object. it also works for functions and methods.
encapsulation
groups the variables and function that are highly related.
abstraction
makes the interface of an object simpler and reduces the impact of change.
inheritance
mechanism to reduce redundant code. functions or states that are shared among objects, can be reused by inheriting from classes.
polymorphism
something occurs in several different forms. eg., you can call the same functional call payout_salary() based on the different object.
python list
an object of class list.
pandas dataframes
like Excel sheets.
constructor
a function that helps you create new objects of this class. each class usually has a constructor.
instance method
a function that applies to a object. you call this function like this variable.method().
txt.lower()
a function that puts a string variable in lowercase.
txt.upper()
a function that puts a string variable in uppercase. the equivalent of having a function: def upper(string) and calling upper(txt).
txt.isalpha()
returns True if all characters in the string are in the alphabet.
txt.strip()
returns a trimmed version of the string. eg. txt.strip(‘I’) removes ‘I’ from I am sterdam.
class method
it is called by using classname.method(). eg. for datetime.today(), datetime is the name of the class and today is the name of the method.
pandas
a very popular python library, specialized in handling spreadsheet data. like a true panda, it handles data by chewing it relentlessly and effortlessly. the name comes from panel datas.
read_csv()
a function from the module pandas, noted as pandas.read_csv(). it is used to read data from a text file where each line is a row of our spreadsheet. columns are separated by a character, eg. ‘\t’. in this case, write sep= ‘\t’.
df
an object with the class DataFrame. it has 360 methods you can call.
head()
a method that can be called to display the first N rows of the spreadsheet by typing df.head().
df.types
an attribute of the object df. it is a value and indicates the type of data in each column.
df[condition]
only shows the rows where the condition is True. a condition can be eg. df[‘item_name’ == ‘Izze’. it is true for rows where the value in columns item_name is equal to the string ‘Izze’.
apply method
applies a function to each element of a column. the results overwrite the current data in the column.
groupby
a method of df. it groups all rows with the same value for a given variable, eg. item_name. df.groupby(‘item_name’) is an object of class pd.DataFrameGroupBy. it has 134 methods.
sum
a method of df.groupby(‘item_name’). it groups all rows by item_name. it is a new spreadsheet with the same column and one row per item_name value. for each column it aggregates the value using sum() (sums all values).
sort_values
a method used to sort the rows of a spreadsheet according to the values in a column.