[Python] Csv資料分割


Posted by mike-hsieh on 2023-12-21

如題,近期由於需要移轉一些資料,使用了Csv檔,但是整份新增會發生內存不足,所以需要分割。

import pandas as pd

# open file
df = pd.read_csv(r'D:\Projects\__Python\table_file_202312201350.csv', sep=',', index_col=False)

# 每個csv保存10萬筆
for i in range(0, len(df), 1000000):
    file_name = r'D:\Projects\__Python\table_file_' + str(i) + '.csv'  # 保存文件路徑以及文件名稱
    df[i:i+1000000].to_csv(file_name.format(i), index=False)

#pandas #Python #splite csv #seperate csv







Related Posts

[HTML BTS] 冒泡? 捕捉?Capturing & Bubbling in DOM Event

[HTML BTS] 冒泡? 捕捉?Capturing & Bubbling in DOM Event

筆記、[NET101] 網路基礎概論 ( 2 )

筆記、[NET101] 網路基礎概論 ( 2 )

 [ 筆記 ] JavaScript 進階 05 - Execution Context - Scope Chain

[ 筆記 ] JavaScript 進階 05 - Execution Context - Scope Chain


Comments