exam 3 lec notes Flashcards
assert statements enable you to convert _____ errors into _______ errors
semantic, runtime
what is the syntax for assert ?
assert BOOLEAN_EXPRESSION
what happens when assert evaluates to true? what about false?
true: nothing happens, moves on
false: assertion error
what type of errors are called ‘exceptions’?
runtime errors
what is ‘catching’ an expression in terms of try and except blocks?
where there is an exception, the try block gets terminated and the except block runs instead
what is ‘e’ in exception?
the object instance, you add it after exception if you want a general overview (?) or your error
what does str(e)?
gives you the reason for the exception
whats does type(e) do?
gives you the type of error
what does raising and error do in python?
explicitly signals something is wrong and explains the error
what does .read() convert the contents in a file to?
a long str
what needs to be explicitly written for writing in a file?
\n
what does os.listdir do?
list all the paths and directories in a directory
what does os.mkdir do?
creates a new directory
what does os.path.isfile do?
returns true if a path points to a file, otherwise returns false
what does os.path.isdir do?
returns true if path points to directory, otherwise it returns false
what does os.path.join do?
joins one or more path components into a single path
what is a pandas series?
a combination of dict and list
what can pandas series be made from?
list or dict
if the ‘exception’ is too broad in a try and except block? what could you do to try and catch a specific error?
you can specify the type of error you want to catch by writing the type after the exception
what is the difference between ‘+’ and ‘append()’ method on lists?
+ operator creates a brand new object instance
append() modifies the existing list object instance
what is a path on python?
a string that represents the location of a file or directory on a computer’s file system
what do you pass as an argument to open(…)?
the relative path, you should not hardcode the ‘/’ or ‘'
what does the read() function return?
the file contents as one big string
what does calling list() on a file do?
converts file contents as a list
what needs to be explicitly written for the ‘w’ mode in open(…) function?
\n
what is os in python?
os stands for operating system, and it is a built in module that allows you to interact with the operating system and access various functions of the platform
what does os.path.join do?
allows you to write code in one OS platform and run it on another
what is pandas?
a software installed on top of python that is a package of tools for doing data science
what is a pandas series? what can it be created from?
a pandas series is a combination of dict and list, it can be created from either a python list or dict
what is an index in python series, what is an integer position in python list?
index is equivalent to a key in python dict
integer position is equivalent to index in python list
how would create a series using d = {‘one’: 7, ‘two’: 3}? (Syntax)
s = pd.Series(d)
or you can add the dictionary as an argument to the series
what is the difference between iloc and loc for Pandas series?
iloc stands for integer location, and can be used to splice the series by rows and column number
loc stands for location and is used to pick out rows and column by it’s label
what does .quantile() do? What is its argument, and what is its defaults?
it enables to calculate percentages
it takes a argument float value between 0 and 1
it defaults to the 50th percentile
what does .value_counts() do?
creates a series where the key is the data, and the value is its count in the Series
default return value is descending order of counts
what does .sort_index() do?
sorts the series in order of values and index, returns a new series
what argument do you need to pass for .sorted_index() to get a series sorted in reverse order?
ascending = False
what are the expressions for booleans for series?
& means ‘and’
I means ‘or’
~ means ‘not’
use () for compound boolean expressions
how must you format boolean expressions for a series?
specify them with a pair of []
what are some forms that can be created into a data frame?
- dictionary of series
- dictionary of lists
- dictionary of dictionaries
- list of dictionaries
- list of lists
to make a dictionary of series, what do you need to write for columns?
the names