繁体   English   中英

从大量 csv 中读取特定数量的 csv

[英]Read a specific number of csvs from larger number of csvs

我有一个 python 脚本,该脚本当前读取文件夹中的 csvs,例如 exp_00.csv-exp_30.csv 以升序排列并创建单词报告。 但是,当循环在特定的 csv 上时,我需要输入一些用户数据。 我有一个行号、运行号和尝试号。 我希望脚本读取特定数量的 csvs 以获取尝试次数。 例如,第 1 行运行 1 尝试 1,...尝试 2,...尝试 3,等等。

目前,该脚本读取第一个 csv,并根据输入的尝试次数,将 1 个 csv 生成为三个字文件。 It should be that exp_00.csv - Attempt 1, exp_01.csv = Attempt 2, exp_03.csv = Attempt 3. Then once the subset of csvs is done, it should loop back and ask the line number, run number, and attempt number再次

我怎样才能让它循环,以便在一定数量的 csvs 之后它停止并再次提出问题?

下面是当前执行循环的部分代码。

files = glob.glob('*.csv')
for count, file in enumerate(sorted(files), start=1):   
    reader = pd.read_csv(open(file, encoding='utf8'), skiprows=3)

    print (f'The files is {file}')

    # Start Line Number
    LineNo = int(input('Please enter the Start Line Number: \n'))

    # Run Number
    RunNo = input("Please enter the Run Number: \n")

    # Attempt Number
    AttemptNo = int(input(f"Please enter the number of csv files for Line {LineNo} and Run {RunNo}: \n"))
    # This should then loop through the csvs for the number entered, generate the reports, and then loop back to ask the LineNo, RunNo, and AttemptNo for the next set of csvs of the specific LineNo and RunNo

#*********************************************************************** Processing Data ********************************************************************************************#
    for iA in range(AttemptNo)[1:]:
    # Loop should go here, the above is my attempt

        NumberOfTables = nm.max(reader)['table']
        for i in range(NumberOfTables):
            variableArray[reader.loc[reader['table']==i]['_field'].iat[0]]=reader.loc[reader['table'] == i]
            globals()[f"{reader.loc[reader['table']==i]['_field'].iat[0]}"] = reader.loc[reader['table'] == i]
            variableAverageArray[reader.loc[reader['table']==i]['_field'].iat[0]] = nm.around((reader.loc[reader['table'] == i].replace(0,nm.NaN)).mean()['_value'],2)
            variableStartArray[reader.loc[reader['table']==i]['_field'].iat[0]] = nm.around(reader.loc[reader['table'] == i]['_value'].iat[0],2)
            df = reader.loc[reader['table'] == i]
            row_ix = df.shape[0]-df.ne(0).values[::-1].argmax(0)-1
            last_max = df.values[row_ix, range(df.shape[1])]
            variableFailureArray[reader.loc[reader['table'] == i]['_field'].iat[0]] = {'FailureValue':last_max[6],'FailurePoint':nm.where(df==last_max[6])[0][-1]}
            variableFailArray[reader.loc[reader['table'] == i]['_field'].iat[0]] = {'FailureValue':nm.max(df)['_value'],'FailurePoint':nm.where(df == nm.max(df['_value']))[0][-1]}

任何帮助表示赞赏。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM