drop columns pandas
df.drop(columns=['B', 'C'])
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']
)
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