Python Pandas2 DataFrames Flashcards
What is an iterator function in Pandas?
An iterable is any Python object capable of returning its members one at a time, permitting it to be iterated over in a for-loop.
What does the zip function do?
The zip() function in Python takes two or more iterables (like lists, tuples, or strings) and returns an iterator of tuples, where each tuple contains elements from the corresponding positions in the input iterables.
How do you build a hierarchical index in a DataFrame?
How do you give a name to an index?
df.index. names = [‘Parent’, ‘Child’]
How do you select a value in a hierarchical DataFrame?
Traverse the row hierarchy first, then do the column. Like this: df.loc[‘Parent1’].loc[‘Child2’].[‘Column1’]
What is the difference between the location function (loc) and the cross-section function (xs)?
How would you get rid of the rows (or columns) that have NaN values?
df.dropna(axis=0)
How would you get rid of the rows that may have NaN values but at least have N non-NaN values?
df.dropna(axis=0, thresh = 2)
How can you programmatically fill in NaN values with something? (Python’s version of nafill)
use the fillna function, for example, df.fillna(value= 0) or df.fillna(value = df.mean())) NOTE TO SELF, TRY THIS OUT.