Arvinth Kumar
Arvinth Kumar

Reputation: 1014

Convert the datatype of elements in list - Python

I have a list 'column_names' in below format.

['Date', array(['Total'], dtype=object), array(['All Delinq'], dtype=object), array(['FL892150005'], dtype=object), array(['Fed Rsv Percent Balance 90+ Da'], dtype=object), array(['Market'], dtype=object), array(['Final US Composite SA'], dtype=object)]

I need to convert all items in list to string.

['Date', 'Total', 'All Delinq', 'FL892150005', 'Fed Rsv Percent Balance 90+ Da', 'Market', 'Final US Composite SA']

Please help.

Upvotes: 0

Views: 383

Answers (1)

ximi hoque
ximi hoque

Reputation: 66

from numpy import array
arr = ['Date', array(['Total'], dtype=object), array(['All Delinq'], 
   dtype=object), array(['FL892150005'], dtype=object), array(['Fed Rsv Percent 
   Balance 90+ Da'], dtype=object), array(['Market'], dtype=object), array(['Final 
   US Composite SA'], dtype=object)]

arr_updated = [i if type(i)==str else i[0] for i in arr ]

Upvotes: 2

Related Questions