我有一個巨大的數據庫;並且一些線路被重複。我可以使用「unique()」功能,但需要5分鐘。有沒有辦法(也許是一種並行編程方式)做同樣的事情?並行方式從DataFrame中提取唯一元素存在嗎?
0
A
回答
0
我不知道這是否會更快,但你可以使用distinct
從dplyr
這樣的:
df %>% distinct(x)
另一種選擇是使用group_by
(也是從dplyr
):
df %>% group_by(x)
0
檢查data.table
包。這裏是你可以做什麼:
set.seed(1)
df <- data.frame(col1 = sample(x = 5000, size = 1e6, replace = TRUE),
col2 = sample(x = 5000, size = 1e6, replace = TRUE))
dt <- copy(df)
setDT(dt) #here you convert a data.frame object into a data.table one by reference
unique(dt)
我們可以檢查使用microbenchmark
包時間增益:
microbenchmark(unique(df), unique(dt))
# Unit: milliseconds
# expr min lq mean median uq max neval
# unique(df) 1028.92260 1285.39321 1410.4072 1405.7486 1543.1486 1857.4901 100
# unique(dt) 83.11946 98.41596 148.0874 119.0889 155.0679 507.4944 100
相關問題
- 1. 如何從Scala中的類列表中提取唯一元素
- 2. 使用Javascript提取唯一元素ID
- 3. 從矢量中提取唯一的部分元素
- 4. 正則表達式 - 在一行中提取多個元素
- 5. 從html頁面中提取元素的最佳方式?
- 6. 從頁面3中存在的mysql中提取唯一記錄
- 7. 獲取集合中的唯一元素
- 8. DataFrame元素按行排序
- 9. 提取元素,並用長
- 10. 使setInterval對元素唯一嗎?
- 11. 提取數組中的唯一元素(從K和R C ex1-14開始)
- 12. 從PySpark DataFrame列中刪除元素
- 13. mysql,從列中提取唯一值
- 14. 如何從SQL中提取唯一值?
- 15. 將pandas對象提取到列表中並提取唯一值
- 16. 唯一元素ID
- 17. 從數組中刪除唯一元素的最有效方法
- 18. 如何從無ArrayList的ArrayList中獲取唯一元素
- 19. 從Java中的ArrayList獲取唯一的元素對
- 20. 從更多元素中獲取唯一名稱
- 21. Python/Pandas從DataFrame中篩選出唯一的行
- 22. C++映射唯一類並從值中提取子類
- 23. 從提取鍵/值對的唯一密鑰,並在陣列
- 24. 從R中列表中提取元素?
- 25. 如何在並行循環中從IQueryable中獲取元素
- 26. Python:從stdout中提取模式並保存在csv中
- 27. 多個模式的唯一元素
- 28. 獲取唯一元素名稱的XPath
- 29. 如何從一組元素中獲取id並保存在數組中?
- 30. 合併兩個陣列,存儲唯一的元素,並在jQuery的