[英]Reading different tables from a directory into an array of separate dataframes
我在目錄中有幾個CSV文件(表)(所有表都具有不同的架構),並且想要遍歷文件並將每個表讀入一個單獨的數據框中。
有沒有辦法在Python / Pandas中執行此操作-將不同的表讀入數據框數組? 如何將多個表(具有不同的架構)導入到多個單獨的數據框中?
嘗試這個;
import os
import pandas as pd
import glob
os.chdir("E:/") # change this to the directory where your csv files are stored
csv_files = {} # we store the dataframes in a dictionary
for file in glob.glob("*.csv"):
csv_files[file] = pd.read_csv(file)
for dataframe in csv_files.values():
print dataframe
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.