我正在尝试将多个XBRL文件合并到一个Excel/CSV导出中。要合并的文件数量是可变的,取决于指定文件夹中的文件数量。该代码用于将单个文件导出到csv。唯一的区别是文件日期和值,文件中的所有代码/密钥都是相同的。我被困在如何循环通过file_list并将数据合并/解析为导出格式上。第二个目标是创建一个包含所有单个报告dict的dict。
import os, glob, pandas as pd, xbrl, csv
from xbrl import XBRLParser, GAAP, GAAPSerializer
path = 'P:/Bank Research/Bank Automation/Calls'
callCert = '57944'
dates = ['063023','123122','123121','123120','123119','123118']
xbrl_parser = XBRLParser()
file_list = glob.glob(path + "/*.XBRL")
“P:/Bank Research/Bank Automation/Calls\Cert57944_033123.XBRL”,Call_Cert57944_063023.XBRL“,Call_Cert57944_123118.XBRL”,Call_Cert57944_123119.XBRL“,
xbrl_file = "Call_Cert"+callCert+"_"+dates[0]+".XBRL"
xbrl_document = xbrl_parser.parse(xbrl_file)
custom_obj = xbrl_parser.parseCustom(xbrl_document)
list_bank_numbers = []
list_bank_keys = []
for i in custom_obj():
list_bank_numbers.append(i[1])
list_bank_keys.append(i[0])
bank_dict = {list_bank_keys[i]: list_bank_numbers[i] for i in range(len(list_bank_keys))}
def export_dict_to_csv(dictionary, output_file):
keys = dictionary.keys()
values = dictionary.values()
with open(output_file, 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(keys)
writer.writerow(values)
export_dict_to_csv(bank_dict, callCert+'.csv')
1条答案
按热度按时间ss2ws0br1#