Untitled spreadsheet - Sheet1 Flashcards
1
Q
- What function is used to check for missing values in a DataFrame?
A
df.isnull()
2
Q
- What function is used to check for non-missing values in a DataFrame?
A
df.notnull()
3
Q
- How to count the missing values in a DataFrame?
A
df.isnull().sum()
4
Q
- How to get a total sum of all missing values in a DataFrame?
A
df.isnull().sum().sum()
5
Q
- What function is used to remove rows with missing values?
A
df.dropna()
6
Q
- What parameter should you use in dropna() to remove columns with missing values?
A
axis=1
7
Q
- How to only drop rows where all columns are NaN?
A
df.dropna(how=’all’)
8
Q
- What does df.dropna(thresh=n) do?
A
Drops rows that have less than n non-NaN values
9
Q
- What does df.fillna(value) do?
A
It fills NaN values with a specified ‘value’
10
Q
- How to fill missing values with the previous value in the DataFrame?
A
df.fillna(method=’ffill’)
11
Q
- How to fill missing values with the next value in the DataFrame?
A
df.fillna(method=’bfill’)
12
Q
- How to limit the amount of consecutive NaN filled with the ffill or bfill method?
A
df.fillna(method=’ffill’, limit=n)
13
Q
- How to replace all NaN values with the mean of the DataFrame?
A
df.fillna(df.mean())
14
Q
- How to replace all NaN values with the median of the DataFrame?
A
df.fillna(df.median())
15
Q
- How to replace NaN in a specific column with the mean of that column?
A
df[‘column’].fillna(df[‘column’].mean())
16
Q
- How to replace NaN in a specific column with the median of that column?
A
df[‘column’].fillna(df[‘column’].median())
17
Q
- How to interpolate missing values?
A
df.interpolate()
18
Q
- How to interpolate missing values with a limit?
A
df.interpolate(limit=n)
19
Q
- What does df.interpolate(method=’polynomial’
A
order=2) do?
20
Q
- How to replace NaN values with a specified value in a DataFrame?
A
df.fillna(value)