Answers for "drop list of columns pandas"

18

drop multiple columns pandas

yourdf.drop(['columnheading1', 'columnheading2'], axis=1, inplace=True)
Posted by: Guest on May-16-2020
8

drop columns pandas

df.drop(columns=['B', 'C'])
Posted by: Guest on March-23-2020
1

drop list of columns pandas

df.drop([item for item in total_cols if item not in columns_in_use], axis=)
Posted by: Guest on May-05-2021
1

remove columns from a dataframe python

df = df.drop(df.columns[[0, 1, 3]], axis=1)  # df.columns is zero-based pd.Index
Posted by: Guest on May-20-2020
0

python - dataframe columns is a list - drop

# Df with a coulmn (dims) that contain list
key1 = 'site channel fiscal_week'.split()
key2 = 'site dude fiscal_week'.split()
key3 = 'site eng fiscal_week'.split()

keys = pd.DataFrame({'key': [1,2,3],
                     'dims': [key1,key2,key3]})

# Output
                         dims  key
[site, channel, fiscal_week]    1
[site, dude, fiscal_week]       2
[site, eng, fiscal_week]        3


# Solution
keys['reduced_dims'] = keys['dims'].apply(
    lambda row: [val for val in row if val != 'fiscal_week']
)
Posted by: Guest on February-17-2021
-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
Posted by: Guest on April-12-2021

Browse Popular Code Answers by Language