以下是一些標題選項,每個標題選項都強調解決方案的不同方面: 聚焦問題: * 如何在沒有記憶體錯誤的情況下處理大型 Pandas DataFrame? * Pandas 中的記憶體錯誤:

Patricia Arquette
發布: 2024-10-27 06:19:29
原創
828 人瀏覽過

Here are a few title options, each highlighting a different aspect of the solution:

Focusing on the Problem:

* How to Process Large Pandas DataFrames Without Memory Errors?
* Memory Error in Pandas:  Efficiently Handling Large Dataframes?

Focusing on t

切片大型Pandas 資料幀

問題:

問題:
  1. 問題:
  2. 錯誤,表示資料幀大小過大。目標是:

將資料幀分成更小的段。

迭代函數內的較小的區塊。

將處理後的段合併到單一資料幀中。

解:
<code class="python">n = 200000  # Chunk row size
list_df = [df[i:i + n] for i in range(0, df.shape[0], n)]</code>
登入後複製
<code class="python">list_df = np.array_split(df, math.ceil(len(df) / n))</code>
登入後複製

以行數切片

可以使用list 來完成固定行數的分割來自numpy 的理解或array_split:

<code class="python">list_df = []

for n, g in df.groupby('AcctName'):
    list_df.append(g)</code>
登入後複製

按AcctName 切片

以特定列值切片,例如AcctName:
<code class="python">consolidated_df = pd.concat(list_df)</code>
登入後複製
以特定列值進行切片,例如AcctName:合併大數據幀被切片後,可以使用pd.concat 重新組裝:

以上是以下是一些標題選項,每個標題選項都強調解決方案的不同方面: 聚焦問題: * 如何在沒有記憶體錯誤的情況下處理大型 Pandas DataFrame? * Pandas 中的記憶體錯誤:的詳細內容。更多資訊請關注PHP中文網其他相關文章!

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!