Untitled spreadsheet - Sheet1 Flashcards

1
Q
  1. What function is used to check for missing values in a DataFrame?
A

df.isnull()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What function is used to check for non-missing values in a DataFrame?
A

df.notnull()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. How to count the missing values in a DataFrame?
A

df.isnull().sum()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. How to get a total sum of all missing values in a DataFrame?
A

df.isnull().sum().sum()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What function is used to remove rows with missing values?
A

df.dropna()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What parameter should you use in dropna() to remove columns with missing values?
A

axis=1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How to only drop rows where all columns are NaN?
A

df.dropna(how=’all’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What does df.dropna(thresh=n) do?
A

Drops rows that have less than n non-NaN values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. What does df.fillna(value) do?
A

It fills NaN values with a specified ‘value’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. How to fill missing values with the previous value in the DataFrame?
A

df.fillna(method=’ffill’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. How to fill missing values with the next value in the DataFrame?
A

df.fillna(method=’bfill’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. How to limit the amount of consecutive NaN filled with the ffill or bfill method?
A

df.fillna(method=’ffill’, limit=n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. How to replace all NaN values with the mean of the DataFrame?
A

df.fillna(df.mean())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. How to replace all NaN values with the median of the DataFrame?
A

df.fillna(df.median())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. How to replace NaN in a specific column with the mean of that column?
A

df[‘column’].fillna(df[‘column’].mean())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. How to replace NaN in a specific column with the median of that column?
A

df[‘column’].fillna(df[‘column’].median())

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  1. How to interpolate missing values?
A

df.interpolate()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. How to interpolate missing values with a limit?
A

df.interpolate(limit=n)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. What does df.interpolate(method=’polynomial’
A

order=2) do?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  1. How to replace NaN values with a specified value in a DataFrame?
A

df.fillna(value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  1. How to replace various NaN values with different values?
A

df.fillna({‘column1’: value1, ‘column2’: value2})

22
Q
  1. How to replace NaN values in a specific column with a specific value?
A

df[‘column’].fillna(value)

23
Q
  1. How to use forward fill method for replacing NaN values in a specific column?
A

df[‘column’].fillna(method=’ffill’)

24
Q
  1. How to use backward fill method for replacing NaN values in a specific column?
A

df[‘column’].fillna(method=’bfill’)

25
Q
  1. What does interpolate method do with missing data?
A

Interpolate method uses various interpolation technique to guess the missing values from the other values in the DataFrame

26
Q
  1. How to replace NaN values in a DataFrame with the mode?
A

df.fillna(df.mode().iloc[0])

27
Q
  1. What does ‘inplace’ parameter do in fillna
A

dropna methods?

28
Q
  1. How to drop the columns where any value is missing in a DataFrame?
A

df.dropna(axis=’columns’)

29
Q
  1. How to drop the columns where all values are missing in a DataFrame?
A

df.dropna(how=’all’, axis=’columns’)

30
Q
  1. How to keep the DataFrame with valid entries in the same variable?
A

df.dropna(inplace=True)

31
Q
  1. How to replace NaN values in a DataFrame with zero?
A

df.fillna(0)

32
Q
  1. How to drop rows where NaN appear in certain columns only?
A

df.dropna(subset=[‘column1’, ‘column2’])

33
Q
  1. How to use pad method for replacing NaN values in DataFrame?
A

df.fillna(method=’pad’)

34
Q
  1. How to replace missing values in a DataFrame with the value from the previous row or column?
A

df.fillna(method=’pad’)

35
Q
  1. How to fill the missing values in a DataFrame with the most frequent value in a column?
A

df[‘column’].fillna(df[‘column’].mode()[0])

36
Q
  1. How to drop the row if any of the column has missing value in DataFrame?
A

df.dropna(how=’any’)

37
Q
  1. How to drop the row if all of the columns have missing value in DataFrame?
A

df.dropna(how=’all’)

38
Q
  1. How to drop the rows only if missing values are present in the specified columns in DataFrame?
A

df.dropna(subset=[‘column_name’])

39
Q
  1. How to drop the column if any of the value is missing in DataFrame?
A

df.dropna(axis=1, how=’any’)

40
Q
  1. How to drop the column if all of the values are missing in DataFrame?
A

df.dropna(axis=1, how=’all’)

41
Q
  1. How to keep the DataFrame with non NaN values in the same variable?
A

df.dropna(inplace=True)

42
Q
  1. How to replace NaN values in a DataFrame with a constant text?
A

df.fillna(‘CONSTANT’)

43
Q
  1. How to replace NaN values in a DataFrame with an interpolated value?
A

df.interpolate()

44
Q
  1. How to replace NaN values in a DataFrame with the value that comes directly after it in the same column
A

then replace all remaining na with 0?

45
Q
  1. How to replace NaN values in a DataFrame with the mean value of each column?
A

df.fillna(df.mean())

46
Q
  1. How to replace NaN values in a DataFrame with the median value of each column?
A

df.fillna(df.median())

47
Q
  1. How to replace NaN values in a DataFrame with the mode value of each column?
A

df.fillna(df.mode().iloc[0])

48
Q
  1. How to replace NaN values in a DataFrame with the value from the previous row in the same column?
A

df.fillna(method=’ffill’, axis=0)

49
Q
  1. How to replace NaN values in a DataFrame with the value from the next row in the same column?
A

df.fillna(method=’bfill’, axis=0)

50
Q
  1. How to replace NaN values in a DataFrame with an arbitrary value?
A

df.fillna(value)