replace all spacec column with underscore in pandas
import pandas as pd
# remove spaces in columns name
df.columns = df.columns.str.replace(' ','_')
replace all spacec column with underscore in pandas
import pandas as pd
# remove spaces in columns name
df.columns = df.columns.str.replace(' ','_')
remove columns that contain certain names in pandas
df = df.drop(df.filter(regex='Test').columns, axis=1)
drop dataframe columns from list of column names
# Drop The Original Categorical Columns which had Whitespace Issues in their values
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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us