Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

drop list of columns pandas

df.drop([item for item in total_cols if item not in columns_in_use], axis=)
Comment

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
Comment

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']
)
Comment

PREVIOUS NEXT
Code Example
Python :: how to check the size of a file in python 
Python :: input python 
Python :: show columns pandas 
Python :: python mixins 
Python :: rmse python 
Python :: python define an array of dictonary 
Python :: pandas read_csv dtype datetime 
Python :: check anonim user django 
Python :: find the index of a character in a string python 
Python :: pandas sort dataframe by column 
Python :: pandas look for values in column with condition 
Python :: send message from server to client python 
Python :: chatbot python 
Python :: Example of lambda function in python with list 
Python :: check if a list contains any item from another list python 
Python :: install opencv for python 2.7 
Python :: python code to exe file 
Python :: python map string to int 
Python :: random search cv 
Python :: print 2 decimal places python 
Python :: Python datetime to string using strftime() 
Python :: how to use cv2.COLOR_BGR2GRAY 
Python :: python insert sorted list 
Python :: while loop python 
Python :: how to multiply a string in python 
Python :: install python in docker file 
Python :: how to install python dill 
Python :: Python JSON API example 
Python :: suppress python vs try/except 
Python :: python json check if key exists 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =