私はCSVから読み込んでPyTablesに書き込む次のコードを持っています。しかし、pd.read_csvはデータフレームを作成しますが、これはPyTablesでは処理されません。この問題をどうやって解決するのですか?私は素敵な配列を作成することができますが、これは殺し過ぎ、時間がかかる可能性がありますか? (トランザクション・レコードは、私が正しいデータ型で作成したクラスである - 私はnumpyのを使用している場合、これを複製する必要があり)PyTables大きなCSVをチャンクで読む:
def get_transaction_report_in_chunks(transaction_file):
transaction_report_data = pd.read_csv(transaction_file, index_col=None, parse_dates=False, chunksize=500000)
return transaction_report_data
def write_to_hdf_from_multiple_csv(transaction_file_path):
hdf = tables.open_file(filename='MyDB.h5', mode='a')
transaction_report_table = hdf.create_table(hdf.root, 'Transaction_Report_Table_x', Transaction_Record, "Transaction Report Table")
all_files = glob.glob(os.path.join(transaction_file_path, "*.csv"))
for transaction_file in all_files:
for transaction_chunk in get_transaction_report_in_chunks(transaction_file):
transaction_report_table.append(transaction_chunk)
transaction_report_table.flush()
hdf.Close()
標準のPandas 'DataFrame.to_hdf()'や 'HDFStore.append'などを使用しないのには良い理由はありますか? – MaxU
本当にありません。大規模なデータセットや特定の列のテーブルを照会するのに十分なのかどうかはわかりません。もう1つの問題は、クエリでメモリ内で計算できない結果が返された場合です。これをどのように処理するのかはわかりません。 – CodeGeek123