remove columns names from dataframe pandas code example
Example 1: how to drop a column by name in pandas
>>> df.drop(columns=['B', 'C'])
A D
0 0 3
1 4 7
2 8 11
Example 2: drop dataframe columns from list of column names
df.drop(cat_columns, axis = 1, inplace = True)
dict_1 = {'workclass_stripped':'workclass', 'education_stripped':'education',
'marital-status_stripped':'marital_status', 'occupation_stripped':'occupation',
'relationship_stripped':'relationship', 'race_stripped':'race',
'sex_stripped':'sex', 'native-country_stripped':'native-country',
'Income_stripped':'Income'}
df.rename(columns = dict_1, inplace = True)
df