有沒有辦法從 PDF 表格中匯入旋轉文本,例如 python 中的 tabula-py?
我意識到在這種情況下我可以重命名列標題,但我想知道是否有辦法設定用于匯入旋轉文本的引數。我沒有在 tabula-py 的 readthedocs 中看到任何關于旋轉的提及,也沒有找到其他可以做到這一點的軟體包(盡管我確實看到提到旋轉整個頁面——這不適合這個用例就像重命名列會更容易一樣)。
例子:
import tabula
list_df = tabula.read_pdf(
'https://sos.oregon.gov/elections/Documents/statistics/G22-Daily-Ballot-Returns.pdf',
pages=3
)
list_df[0]

uj5u.com熱心網友回復:
我剛剛嘗試使用 camelot,它正確地讀取了列標題中的旋轉文本:這就是結果。
uj5u.com熱心網友回復:
正如@Francesco 所提到的,camelot 有一種特殊的方式比 tabula-py 更好,因為 camelot 找到了旋轉的文本。
安裝 camelot 是一個艱難的程序,所以我想在這里分享我的一些經驗。
- camelot 的依賴:代筆 https://camelot-py.readthedocs.io/en/master/user/install-deps.html
對于 Mac brew install ghostscript tcl-tk,然后解決任何錯誤(對我來說有很多錯誤,但在復制粘貼每個錯誤后,彩虹盡頭有金色)。
- camelot 安裝概述https://camelot-py.readthedocs.io/en/master/user/install.html
在 Mac 上:
pip install "camelot-py[cv]"
檔案頁面目前實際上說的是 [base] 而不是 [cv],但在上面的評論中它說的是 [cv](而堆疊溢位文章說的是 [cv])。
- 在 python 中(如果您使用的是 jupyter notebook,請重新啟動 notebook 內核)
通過以下內容,可以很好地讀取旋轉的列標題。
import camelot
tables = camelot.read_pdf(
'https://sos.oregon.gov/elections/Documents/statistics/G22-Daily-Ballot-Returns.pdf',
pages='all')
tables[3].df
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/536322.html
