問題描述
我做了大量的統計工作,并使用 Python 作為我的主要語言.雖然我使用的一些數據集可能占用 20GB 的內存,這使得使用 numpy、scipy 和 PyIMSL 中的內存函數對它們進行操作幾乎是不可能的.統計分析語言 SAS 在這里有一個很大的優勢,它可以對來自硬盤的數據進行操作,而不是嚴格的內存處理.但是,我想避免在 SAS 中編寫大量代碼(出于各種原因),因此我試圖確定我對 Python 有哪些選擇(除了購買更多的硬件和內存).
I do a lot of statistical work and use Python as my main language. Some of the data sets I work with though can take 20GB of memory, which makes operating on them using in-memory functions in numpy, scipy, and PyIMSL nearly impossible. The statistical analysis language SAS has a big advantage here in that it can operate on data from hard disk as opposed to strictly in-memory processing. But, I want to avoid having to write a lot of code in SAS (for a variety of reasons) and am therefore trying to determine what options I have with Python (besides buying more hardware and memory).
我應該澄清一下,像 map-reduce 這樣的方法對我的大部分工作沒有幫助,因為我需要對 完整 組數據進行操作(例如計算分位數或擬合邏輯回歸模型).
I should clarify that approaches like map-reduce will not help in much of my work because I need to operate on complete sets of data (e.g. computing quantiles or fitting a logistic regression model).
最近我開始玩 h5py 并認為這是我找到的最佳選擇允許 Python 像 SAS 一樣操作并操作磁盤中的數據(通過 hdf5 文件),同時仍然能夠利用 numpy/scipy/matplotlib 等.我想知道是否有人在類似的設置中使用 Python 和 h5py 的經驗和他們發現了什么.有沒有人能夠在迄今為止由 SAS 主導的大數據"設置中使用 Python?
Recently I started playing with h5py and think it is the best option I have found for allowing Python to act like SAS and operate on data from disk (via hdf5 files), while still being able to leverage numpy/scipy/matplotlib, etc. I would like to hear if anyone has experience using Python and h5py in a similar setting and what they have found. Has anyone been able to use Python in "big data" settings heretofore dominated by SAS?
購買更多的硬件/內存肯定會有所幫助,但從 IT 的角度來看,我很難將 Python 賣給需要分析大量數據集的組織,而 Python(或 R,或 MATLAB 等)需要持有內存中的數據.SAS 在這方面繼續擁有強大的賣點,因為雖然基于磁盤的分析可能較慢,但您可以自信地處理龐大的數據集.所以,我希望 Stackoverflow 能幫助我弄清楚如何降低使用 Python 作為主要大數據分析語言的風險.
Buying more hardware/memory certainly can help, but from an IT perspective it is hard for me to sell Python to an organization that needs to analyze huge data sets when Python (or R, or MATLAB etc) need to hold data in memory. SAS continues to have a strong selling point here because while disk-based analytics may be slower, you can confidently deal with huge data sets. So, I am hoping that Stackoverflow-ers can help me figure out how to reduce the perceived risk around using Python as a mainstay big-data analytics language.
推薦答案
我們使用Python結合h5py、numpy/scipy和boost::python來做數據分析.我們的典型數據集大小可達數百 GB.
We use Python in conjunction with h5py, numpy/scipy and boost::python to do data analysis. Our typical datasets have sizes of up to a few hundred GBs.
HDF5 的優勢:
- 可以使用 h5view 應用程序、h5py/ipython 和 h5* 命令行工具方便地檢查數據
- API 可用于不同的平臺和語言
- 使用組構造數據
- 使用屬性注釋數據
- 無憂的內置數據壓縮
- 單個數據集上的 io 速度很快
HDF5 陷阱:
- 如果 h5 文件包含太多數據集/組 (> 1000),性能會下降,因為遍歷它們非常慢.另一方面,io 對于一些大型數據集來說速度很快.
- 高級數據查詢(類似 SQL)實施起來笨拙且速度慢(在這種情況下考慮 SQLite)
- HDF5 并非在所有情況下都是線程安全的:必須確保使用正確的選項編譯庫
- 更改 h5 數據集(調整大小、刪除等)會增大文件大小(在最好的情況下)或不可能(在最壞的情況下)(必須復制整個 h5 文件以再次展平)
這篇關于有使用 h5py 在 Python 中對大數據進行分析工作的經驗嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!