代码之家  ›  专栏  ›  技术社区  ›  Arvinth Kumar

转换list-Python中元素的数据类型

  •  -1
  • Arvinth Kumar  · 技术社区  · 6 年前

    我有下面格式的“列名”列表。

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

    我需要将列表中的所有项转换为字符串。

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

    1 回复  |  直到 6 年前
        1
  •  2
  •   ximi hoque    6 年前
    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 ]