【问题标题】:Concatenate multi-column text files containing numbers & nan连接包含数字和 nan 的多列文本文件
【发布时间】:2019-06-11 12:51:37
【问题描述】:

我有一个名为 17307 的文件夹,其中包含一些 .ismr 文件(基本上只是 CSV 文件),名称类似于

SEPT307A.17_.ismr, 
SEPT307B.17_.ismr, 
SEPT307C.17_.ismr,.... upto SEPT307X.17_.ismr. 

我想使用 Python 将所有这些连接到一个文本文件中。我试过了:

st = 'path/to/folder'
a = input('Enter first part of file') #i.e. SEPT307 in file name
alph = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X']
yr = input('enter the year')
last = '_.ismr'
for letter in alph:
    st1 = st + "a" + alph + "." + "yr" + last
    fp = open(st1, "r")
    data=np.append(data, np.fromfile(fp, dtype=list))

即我正在尝试将所有内容放入数据中,然后将数据复制到单独的文本文件中。 但是我收到了这个错误:

TypeError: 无法将 'list' 对象隐式转换为 str

任何人都可以提出一些方法吗?

【问题讨论】:

    标签: python text append concatenation


    【解决方案1】:

    看起来错误来自这一行:

    st1 = st + "a" + alph + "." + "yr" + last
    

    alph 是您的字母表的完整列表。应该是:

    st1 = st + "a" + letter + "." + "yr" + last
    

    问题是您试图将liststr 连接起来。

    【讨论】:

      猜你喜欢
      • 2019-05-14
      • 1970-01-01
      • 2014-10-08
      • 1970-01-01
      • 1970-01-01
      • 2016-03-17
      • 2021-06-26
      • 2012-05-11
      • 2019-03-01
      相关资源
      最近更新 更多