tony selcuk
tony selcuk

Reputation: 687

Filtering Multi Array Strings

I want to write a numpy funcction that filters the a array to only the ones that end with USD and USDC. The function below only works with one filter but does not work with two filters 'USD', 'USDC'. Code has been gotten from issue:issue

import numpy as np

a = np.array(['BTCUSD', 'ETHUSD', 'David', 'georGe', 'XRPUSD', 'USDAUD', 'ETHUSDC'])
print(a[np.char.endswith(a, 'USD', 'USDC')])

Upvotes: 0

Views: 24

Answers (1)

Amit Nanaware
Amit Nanaware

Reputation: 3346

try this:

import numpy as np

a = np.array(['BTCUSD', 'ETHUSD', 'David', 'georGe', 'XRPUSD', 'USDAUD', 'ETHUSDC'])
b = np.array([i for i in a if i.endswith('USDC') or i.endswith('USD')])
print(b)

Upvotes: 1

Related Questions