Intro to python for data science
Boolean
True
and False
, First letter should be uppercase.
Delete list elements
Finally, you can also remove elements from your list. You can do this with the del statement:
|
|
More explicit copy
Do list copy with list() or by using [:].
Functions
|
|
Ironically, you have to ask for information about a function with another function: help()
List methods
upper()
str.upper()
: Notice from the printouts that the upper()
method does not change the object it is called on.
index()
, to get the index of the first element of a list that matches its input andcount()
, to get the number of times an element appears in a list.append(), that adds an element to the list it is called on,
- remove(), that removes the first element of a list that matches the input, and
- reverse(), that reverses the order of the elements in the list it is called on.
Numpy
|
|
Use np.array()
to create a numpy array
|
|
numpy arrays slicing including the start element, excluding the end element.
|
|
Intermediate Python for data science
Matplotlib.pyplot
Build a histogram (1)
|
|
Build a histogram (2): bins
|
|
Labels
|
|
Additional Customizations
|
|
Dictionary manipulation
|
|
Pandas
Dictionary to DataFrame
|
|
CSV to DataFrame
|
|
Square brackets
- The single bracket version gives a Pandas Series, the double bracket version gives a Pandas DataFrame.
|
|
- You can only select rows using square brackets if you specify a slice, like 0:4. Also, you’re using the integer indexes of the rows here, not the row labels!
|
|
loc
and iloc
|
|
Logic, Control Flow and Filtering
Comparison
Remember that for string comparison, Python determines the relationship based on alphabetical order.
|
|