![](/img/trans.png)
[英]Python PANDAS: Converting from pandas/numpy to dask dataframe/array
[英]Converting an DataFrame from pandas to dask
我遵循了這個文檔dask.dataframe.from_pandas並且有稱為npartitions
和chunksize
可選參數。
所以我試着寫這樣的東西:
import dask.dataframe as dd
import pandas as pd
df = pd.DataFrame(...)
df = dd.from_pandas(data=df)
它會引發錯誤消息: ValueError: Exactly one of npartitions and chunksize must be specified.
我想知道如何解決它,我應該如何在調用dask.dataframe.read_csv
像 Dask 一樣計算npartitions
或chunksize
?
在構建 Dask 數據幀之前,您需要選擇npartitions
(分區數)或chunksize
(每個分區的大小)。 您需要決定要將 Pandas 數據幀拆分為多少個並行數據幀,或者您希望每個並行數據幀有多大。 理想情況下,您希望根據系統擁有的內存量以及可用的內核數來決定這一點。
可能是DASK中的一個小故障......因為錯誤本身表明我們需要指定npartitions(The number of partitions of the index to create)
或chunksize(The number of rows per index partition to use.)
..
看到這個錯誤-
if (npartitions is None) == (chunksize is None):
raise ValueError("Exactly one of npartitions and chunksize must be specified.")
這里有最佳實踐chunksize
和npartitions
在DASK dataframes
我認為您需要提供 npartitions 或 chunksize。 就我而言,我嘗試了這兩種情況並且效果很好。 但是當我指定兩個參數時,它給了我同樣的錯誤。
因此,指定兩者之一將清除錯誤。
import dask.dataframe as dd
import pandas as pd
df = pd.read_csv(filepath)
dd_df = dd.from_pandas(df, npartitions=100)
或者
dd_df =dd.from_pandas(df, chunksize=100)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.