我有一個日期列一個DASK資料幀doc_date是在范圍12-1-2021來1-2-2022。我想重新磁區并將此 dask 資料幀拆分為 26 個磁區,以便每個磁區在上述日期范圍內只有 1 個日期。
這是我嘗試過的:
doc_dates = [dt.strftime("%Y-%m-%d") for dt in pd.date_range('2021-12-08', '2022-01-02')]
predictions_df = predictions_df.set_index('doc_date')
predictions_df = predictions_df.repartition(divisions=sorted(doc_dates))
但我似乎收到此錯誤:
ValueError: left side of old and new divisions are different
uj5u.com熱心網友回復:
問題是您需要傳遞compute=True到dask.dataframe.set_index以確保資料實際上按日期排序,然后才能向repartition命令提供排序的日期串列:
predictions_df = predictions_df.set_index('doc_date', compute=True)
predictions_df = predictions_df.repartition(divisions=sorted(doc_dates))
或者,您可以使用divisions引數dask.dataframe.set_index:
predictions_df = predictions_df.set_index(
'doc_date',
divisions=sorted(doc_dates),
compute=True,
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/403832.html
標籤:
