如何做圖片 網(wǎng)站 鏈接廣州商務(wù)網(wǎng)站建設(shè)
利用 TableGeneration 生成多樣化表格數(shù)據(jù)
- TableGeneration 簡介
- 環(huán)境準(zhǔn)備
- chrome瀏覽器(Linux下推薦)
- 火狐瀏覽器(Mac下推薦)
- 生成表格
- 生成表格
- 參數(shù)說明
- 結(jié)論
在數(shù)據(jù)生成和處理領(lǐng)域,表格數(shù)據(jù)的生成是一個(gè)常見需求,尤其是在機(jī)器學(xué)習(xí)和數(shù)據(jù)分析領(lǐng)域。今天,我們將介紹一個(gè)名為 TableGeneration 的工具,它可以幫助我們生成具有多種配置參數(shù)的表格數(shù)據(jù)。這個(gè)工具不僅支持生成不同行列數(shù)的表格,還可以模擬真實(shí)世界中的表格特性,如合并單元格和著色單元格。
TableGeneration 簡介
TableGeneration 是一個(gè)基于 Python 開發(fā)的工具,它利用瀏覽器渲染技術(shù)生成表格圖像。這個(gè)工具的特點(diǎn)在于其高度的可配置性,用戶可以根據(jù)需求自定義表格的多種屬性。生成的表格可以用于各種場景,如數(shù)據(jù)分析和機(jī)器學(xué)習(xí)中的數(shù)據(jù)集構(gòu)建。
GitHub 頁面
環(huán)境準(zhǔn)備
安裝python包
pip3 install -r requirements.txt
目前支持使用chrome瀏覽器和火狐瀏覽器,使用方式分別如下
chrome瀏覽器(Linux下推薦)
- 安裝chrome瀏覽器和中文字體
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
apt-get update && sudo apt-get install libnss3
apt-get install xfonts-wqy
apt install ttf-wqy-zenhei
apt install fonts-wqy-microhei
# refresh fonts
fc-cache -fv
- 安裝chrome瀏覽器驅(qū)動(dòng) chromedriver
首先在官網(wǎng)下載適合自己系統(tǒng)的驅(qū)動(dòng)文件。然后執(zhí)行下列命令
unzip chromedriver_linux64.zip
cp chromedriver /usr/local/share/
ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
- 測試瀏覽器和chromedriver
使用如下命令測試chromedriver和chrome瀏覽器是否安裝正確
from selenium import webdriveroptions = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https:www.baidu.com')
print(driver.title)
driver.close()
如果成功,會(huì)在終端看見如下輸出
百度一下,你就知道
火狐瀏覽器(Mac下推薦)
- 安裝火狐瀏覽器和中文字體
apt-get -y install firefox
apt-get install xfonts-wqy
apt install ttf-wqy-zenhei
apt install fonts-wqy-microhei
# refresh fonts
fc-cache -fv
- 安裝火狐瀏覽器驅(qū)動(dòng) geckodriver
首先在官網(wǎng)下載適合自己系統(tǒng)的驅(qū)動(dòng)文件。然后執(zhí)行下列命令
tar -xf geckodriver-v0.31.0-linux64.tar.gz
cp geckodriver /usr/local/share/
ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver
ln -s /usr/local/share/geckodriver /usr/bin/geckodriver
- 測試瀏覽器和geckodriver
使用如下命令測試geckodriver和火狐是否安裝正確
from selenium import webdriveroptions = webdriver.FirefoxOptions()
options.add_argument('--headless')
driver = webdriver.Firefox(firefox_options=options)
driver.get('https:www.baidu.com')
print(driver.title)
driver.close()
如果成功,會(huì)在終端看見如下輸出
百度一下,你就知道
生成表格
生成表格
使用如下命令可生成表格,ch_dict_path
和en_dict_path
不指定時(shí),將會(huì)使用默認(rèn)的中英文語料。最終生成的表格圖片,表格html文件和PP-Structure格式標(biāo)注文件會(huì)保存在output
指定路徑下。
# 簡單表格
python3 generate_data.py --output output/simple_table --num=1
# 單元格坐標(biāo)為單元格內(nèi)文字坐標(biāo)的表格
python3 generate_data.py --output output/simple_table --num=1 --cell_box_type='text'
# 彩色單元格表格
python3 generate_data.py --output output/color_simple_table --num=1 --color_prob=0.3
# 清單類表格
python3 generate_data.py --output output/qd_table --num=1 --min_row=10 --max_row=80 --min_col=4 --max_col=8 --min_txt_len=2 --max_txt_len=10 --max_span_row_count=3 --max_span_col_count=3 --max_span_value=20 --color_prob=0 --brower_width=1920 --brower_height=5000
# 大單元格表格
python3 generate_data.py --output output/big_cell_table --num=1 --min_row=6 --max_row=10 --min_col=4 --max_col=8 --min_txt_len=2 --max_txt_len=10 --max_span_row_count=3 --max_span_col_count=3 --max_span_value=10 --color_prob=0 --cell_max_width=100 --cell_max_height=100 --brower_width=1920 --brower_height=1920
參數(shù)說明
讓我們詳細(xì)了解一下 TableGeneration 的一些關(guān)鍵參數(shù):
--output output/qd_table
:指定輸出目錄。這里我們設(shè)置輸出目錄為output/qd_table
。--num=1
:指定生成表格的數(shù)量。這里我們只生成一個(gè)表格。--min_row=10
和--max_row=80
:設(shè)置表格的行數(shù)范圍。表格將包含 10 到 80 行。--min_col=4
和--max_col=8
:設(shè)置表格的列數(shù)范圍。表格將包含 4 到 8 列。--min_txt_len=2
和--max_txt_len=10
:設(shè)置單元格中文本長度的范圍。文本長度將在 2 到 10 個(gè)字符之間。--max_span_row_count=3
和--max_span_col_count=3
:設(shè)置合并單元格的行數(shù)和列數(shù)范圍。合并單元格將最多跨越 3 行和 3 列。--max_span_value=20
:設(shè)置合并單元格中的最大數(shù)值。這里我們設(shè)置最大數(shù)值為 20。--color_prob=0
:設(shè)置單元格著色的概率。這里我們設(shè)置為 0,即不使用顏色。--browser_width=1920
和--browser_height=5000
:設(shè)置生成表格的瀏覽器寬度和高度。這里我們分別設(shè)置為 1920 像素和 5000 像素。
通過這些參數(shù),我們可以生成具有特定行列數(shù)、文本長度、合并單元格特性以及尺寸的表格。
結(jié)論
TableGeneration 是一個(gè)強(qiáng)大且靈活的工具,可以用于生成各種類型的表格數(shù)據(jù)。它的可配置性使得用戶能夠根據(jù)特定需求生成表格,從而在數(shù)據(jù)分析和機(jī)器學(xué)習(xí)項(xiàng)目中模擬真實(shí)世界的表格數(shù)據(jù)。通過簡單的命令行操作,我們可以生成具有不同行列數(shù)、文本長度、合并單元格和尺寸的表格,為我們的項(xiàng)目提供豐富的數(shù)據(jù)支持。
群內(nèi)交流更多技術(shù)
130856474 <-- 在這里