Untitled spreadsheet - Sheet1 Flashcards
- What function is used to check for missing values in a DataFrame?
df.isnull()
- What function is used to check for non-missing values in a DataFrame?
df.notnull()
- How to count the missing values in a DataFrame?
df.isnull().sum()
- How to get a total sum of all missing values in a DataFrame?
df.isnull().sum().sum()
- What function is used to remove rows with missing values?
df.dropna()
- What parameter should you use in dropna() to remove columns with missing values?
axis=1
- How to only drop rows where all columns are NaN?
df.dropna(how=’all’)
- What does df.dropna(thresh=n) do?
Drops rows that have less than n non-NaN values
- What does df.fillna(value) do?
It fills NaN values with a specified ‘value’
- How to fill missing values with the previous value in the DataFrame?
df.fillna(method=’ffill’)
- How to fill missing values with the next value in the DataFrame?
df.fillna(method=’bfill’)
- How to limit the amount of consecutive NaN filled with the ffill or bfill method?
df.fillna(method=’ffill’, limit=n)
- How to replace all NaN values with the mean of the DataFrame?
df.fillna(df.mean())
- How to replace all NaN values with the median of the DataFrame?
df.fillna(df.median())
- How to replace NaN in a specific column with the mean of that column?
df[‘column’].fillna(df[‘column’].mean())
- How to replace NaN in a specific column with the median of that column?
df[‘column’].fillna(df[‘column’].median())
- How to interpolate missing values?
df.interpolate()
- How to interpolate missing values with a limit?
df.interpolate(limit=n)
- What does df.interpolate(method=’polynomial’
order=2) do?
- How to replace NaN values with a specified value in a DataFrame?
df.fillna(value)
- How to replace various NaN values with different values?
df.fillna({‘column1’: value1, ‘column2’: value2})
- How to replace NaN values in a specific column with a specific value?
df[‘column’].fillna(value)
- How to use forward fill method for replacing NaN values in a specific column?
df[‘column’].fillna(method=’ffill’)
- How to use backward fill method for replacing NaN values in a specific column?
df[‘column’].fillna(method=’bfill’)
- What does interpolate method do with missing data?
Interpolate method uses various interpolation technique to guess the missing values from the other values in the DataFrame
- How to replace NaN values in a DataFrame with the mode?
df.fillna(df.mode().iloc[0])
- What does ‘inplace’ parameter do in fillna
dropna methods?
- How to drop the columns where any value is missing in a DataFrame?
df.dropna(axis=’columns’)
- How to drop the columns where all values are missing in a DataFrame?
df.dropna(how=’all’, axis=’columns’)
- How to keep the DataFrame with valid entries in the same variable?
df.dropna(inplace=True)
- How to replace NaN values in a DataFrame with zero?
df.fillna(0)
- How to drop rows where NaN appear in certain columns only?
df.dropna(subset=[‘column1’, ‘column2’])
- How to use pad method for replacing NaN values in DataFrame?
df.fillna(method=’pad’)
- How to replace missing values in a DataFrame with the value from the previous row or column?
df.fillna(method=’pad’)
- How to fill the missing values in a DataFrame with the most frequent value in a column?
df[‘column’].fillna(df[‘column’].mode()[0])
- How to drop the row if any of the column has missing value in DataFrame?
df.dropna(how=’any’)
- How to drop the row if all of the columns have missing value in DataFrame?
df.dropna(how=’all’)
- How to drop the rows only if missing values are present in the specified columns in DataFrame?
df.dropna(subset=[‘column_name’])
- How to drop the column if any of the value is missing in DataFrame?
df.dropna(axis=1, how=’any’)
- How to drop the column if all of the values are missing in DataFrame?
df.dropna(axis=1, how=’all’)
- How to keep the DataFrame with non NaN values in the same variable?
df.dropna(inplace=True)
- How to replace NaN values in a DataFrame with a constant text?
df.fillna(‘CONSTANT’)
- How to replace NaN values in a DataFrame with an interpolated value?
df.interpolate()
- How to replace NaN values in a DataFrame with the value that comes directly after it in the same column
then replace all remaining na with 0?
- How to replace NaN values in a DataFrame with the mean value of each column?
df.fillna(df.mean())
- How to replace NaN values in a DataFrame with the median value of each column?
df.fillna(df.median())
- How to replace NaN values in a DataFrame with the mode value of each column?
df.fillna(df.mode().iloc[0])
- How to replace NaN values in a DataFrame with the value from the previous row in the same column?
df.fillna(method=’ffill’, axis=0)
- How to replace NaN values in a DataFrame with the value from the next row in the same column?
df.fillna(method=’bfill’, axis=0)
- How to replace NaN values in a DataFrame with an arbitrary value?
df.fillna(value)