Python Pandas2 DataFrames Flashcards

1
Q

What is an iterator function in Pandas?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does the zip function do?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you build a hierarchical index in a DataFrame?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you give a name to an index?

A

df.index. names = [‘Parent’, ‘Child’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you select a value in a hierarchical DataFrame?

A

Traverse the row hierarchy first, then do the column. Like this: df.loc[‘Parent1’].loc[‘Child2’].[‘Column1’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between the location function (loc) and the cross-section function (xs)?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How would you get rid of the rows (or columns) that have NaN values?

A

df.dropna(axis=0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How would you get rid of the rows that may have NaN values but at least have N non-NaN values?

A

df.dropna(axis=0, thresh = 2)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can you programmatically fill in NaN values with something? (Python’s version of nafill)

A

use the fillna function, for example, df.fillna(value= 0) or df.fillna(value = df.mean())) NOTE TO SELF, TRY THIS OUT.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly