Skip to content

Column Removal Methods

CRM-1: del statement

del df['A']
In-place removal of a column using the Python del statement.

Not Supported

CRM-2: drop method

df = df.drop('A', axis=1)
Returns a new DataFrame with the specified column removed.

Not Supported

CRM-3: drop with columns

df = df.drop(columns=['A', 'B'])
More explicit way to drop columns using the columns parameter.

Not Supported

CRM-4: drop multiple

df = df.drop(['A','B'], axis=1)
Removes multiple columns at once using a list of column names.

Not Supported

CRM-5: pop method

removed = df.pop('A')
Removes a column from the DataFrame and returns it as a Series.

Not Supported

CRM-6: Assign None

df = df.assign(col=None)
Indirect method of column removal by assigning None (not common).

Not Supported

CRM-7: Select subset

df = df[['A', 'B']]
Keeps only the specified columns, effectively removing all others.

Not Supported

CRM-8: loc selection

df = df.loc[:, ['A', 'B']]
Label-based selection that keeps only the specified columns.

Not Supported

CRM-9: iloc selection

df = df.iloc[:, [0, 1]]
Position-based selection that keeps only columns at specified indices.

Not Supported

CRM-10: Boolean mask

df = df.loc[:, ~df.columns.str.startswith('temp')]
Uses boolean masking to remove columns based on conditions.

Not Supported

CRM-11: filter method

df = df.filter(regex='^[AB]')
Keeps columns that match certain patterns, removing all others.

Not Supported

CRM-12: drop_duplicates

df = df.T.drop_duplicates().T
Can indirectly remove columns when applied after transposing.

Not Supported

CRM-13: reindex

df = df.reindex(columns=['A','B'])
Keeps only specified columns and reorders them, removing all others.

Not Supported