![](/img/trans.png)
[英]python - how to create a dictionary with a lot of dataframes using a glob.glob
[英]How to output a lot of lists with data into one giant list after reading in multiple files using glob.glob?
我試圖弄清楚在讀取多個文件並對它們進行一些分析之后如何將一些數據輸出到一個大列表中。 我的實際腳本長數百行,所以我只作總結:
for input_file in glob.glob(os.path.join(input_path, '*.csv')):
data1 = []
data2 = []
fileName = base = os.path.basename(input_file)
with open(input_file, 'r', newline='') as f:
reader = csv.reader(f)
#really long for loop doing stuff to fill the data# lists for
#each file such as file1.csv, file2.csv etc.
new_header = ["File name", "data1", "data2"]
#for row in something....?
#fill all_data with the filenames and data in this format (see link)
#http://dpaste.com/23YFSG7.txt
好的,因此該鏈接在這3列中顯示了我想要的輸出,但是我不知道如何到達那里。 到目前為止,我的腳本已經存儲了每個文件名所需的數據,data1 = []和data2 = []列表,但我還不太清楚如何將它們全部合並為一個巨大的列表,以便於編寫文件稍后。
有任何想法嗎?
您是否要水平合並列表?
first_row = True
for r1, r2 in zip(data1, data2):
if first_row:
print(input_file, r1, r2) # write co CSV file...
first_row = False
else:
print("\t", r1, r2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.