简体   繁体   中英

Removing a list of elements from a list of elements

I have a list of elements. I want to remove three of these elements at the same time.

I tried doing a list comprehension type of a thing. log_r.columns is an array of the column names from a pd.DataFrame() . This is what it looks like:

array(['MBI10', 'SAX', 'PX', 'CAC40', 'CRBEX', 'SOFIX', 'DAX', 'SBITOP', 'BELEX15', 'UAX', 'SASX10', 'AEX', 'BET', 'BUX'], dtype=object) .

I want to remove 'AEX' , 'DAX' and 'CAC40'

emerging_names = log_r.columns.values[log_r.columns.values != ['AEX','DAX','CAC40']]


FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison

Any help is appreciated!

Use Index.isin with inverting mask by ~ :

emerging_names = log_r.columns.values[~log_r.columns.isin(['AEX','DAX','CAC40'])]

Or use list comprehension with filtering:

emerging_names = [x for x in log_r.columns if x not in ['AEX','DAX','CAC40']]

Or if not problem with sorted columns names use Index.difference :

emerging_names = log_r.columns.difference(['AEX','DAX','CAC40'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM