【问题标题】:Reading in a .cat file that is a talbe into Pandas将作为表格的 .cat 文件读入 Pandas
【发布时间】:2021-08-03 21:20:59
【问题描述】:

我正在尝试将大量“.cat”(目录)文件读入 panda 表,以便更轻松地操作数据。我不熟悉“.cat”文件,但在这种情况下,每个文件看起来都像一个包含列和数据的文本文件表。我尝试使用 pd.read_csv(filename) ,因为我认为它是空格分隔的,不是逗号分隔的,而是类似的。

clustname = ["SpARCS-0035", "SpARCS-0219", "SpARCS-0335", "SpARCS-1034", "SpARCS-1051", "SpARCS-1616",\
             "SpARCS-1634", "SpARCS-1638", "SPTCL-0205", "SPTCL-0546", "SPTCL-2106"]
for iclust in range(len(clustname)):
    rfcolpath = restframe + 'RESTFRAME_MASTER_' + clustname[iclust] + '_indivredshifts.cat'

    rfcol_table[iclust] = pd.read_csv(rfcolpath[iclust], engine='python')
    
    rfcol_table.head() 

我得到“ParserError:错误标记数据。C 错误:在源上调用 read(nbytes) 失败。尝试 engine='python'。”作为一个错误。所以我尝试在 read_csv 命令中添加“engine = 'python'”并得到这个错误:“IsADirectoryError: [Errno 21] Is a directory:'/'”。我不知道这意味着什么或如何解决它,我应该如何阅读每个单独的文件?感谢您的帮助!

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    试试这个

    import subprocess
    import pandas as pd
    
    df = pd.DataFrame()
    task = subprocess.Popen(["cat file.txt"], stdout=subprocess.PIPE)
    for line in task.stdout:
        df=pd.concat([df, line])
    task.wait()
    

    【讨论】:

    • 我得到一个错误代码:“OSError: [Errno 8] Exec format error: '/home/caelan/GOGREEN_TEMP/DR1/PHOTOMETRY/RESTFRAME_COLOURS/RESTFRAME_MASTER_SpARCS-0035_indivredshifts.c​​at'”
    • Popen 的目标不可执行时也可能出现此错误。
    猜你喜欢
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 2014-12-12
    相关资源
    最近更新 更多