SBad
SBad

Reputation: 1345

convert an array into a list of objects

All,

I have a dataframe which I am using to extract all unique identifiers as follows:

myTradeFrame['coll_cusip'].unique()

the output is:

array(['BRSUJX0F8', 'BRSU17NB8', '010831BE4', ..., '912828J84',
       '912828R36', '912810RC4'], dtype=object)

How can I convert that array into something that looks like this:

('BRSUJX0F8', 'BRSU17NB8', '010831BE4', ..., '912828J84',
           '912828R36', '912810RC4')

Many Thanks

Upvotes: 0

Views: 81

Answers (3)

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48337

Since myTradeFrame['coll_cusip'].unique() returns a numpy array, use tuple method.

array = myTradeFrame['coll_cusip'].unique()
list = tuple(array)

Upvotes: 2

ignoring_gravity
ignoring_gravity

Reputation: 10476

To get it to return something in the form you asked for (which isn't a list but a tuple), you should use tuple:

tuple(myTradeFrame['coll_cusip'].unique())

Upvotes: 3

gyx-hh
gyx-hh

Reputation: 1431

you can just do this myTradeFrame['coll_cusip'].unique().tolist()

Upvotes: 0

Related Questions