Editing
Comparison of common data file formats in Mandarin
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
拿到資料檔案該怎麼開?各格式限制與注意事項 {{LanguageSwitcher | content = [[Comparison of common data file formats | EN]], [[Comparison of common data file formats in Mandarin | 漢字]] }} == 常見資料格式與限制 == === 1. CSV 檔案 === CSV 檔案:不同欄位值用逗號間隔。 CSV 格式本身沒有筆數上限,限制來自開啟它的軟體。<ref>Row Zero — CSV Row Limits by Spreadsheet: https://rowzero.com/blog/csv-row-limit</ref> 常見問題是 大部分人會使用 Microsoft Excel 開啟 CSV, (1) 中文亂碼:點選兩下發現中文亂碼,檔首需要額外加上 BOM 符號,或者改用匯入檔案方式,才不會遇到亂碼、(2) 如果欄位值包含換行符號的話,Excel 容易會出錯,導致明明是同一筆資料,卻出現在下一筆而出現欄位錯置的錯誤。(3) 資料類型強迫轉換:常見的問題是手機號碼的第一位號碼 0 被吃掉,因為被強制轉換成整數。 如果你拿到是包含換行符號欄位值的 CSV 檔案,則不建議使用 Excel,而是改用 LibreOffice Calc。 === 2. TSV 檔案 === TSV 檔案:不同欄位值用定位鍵 (TAB) 間隔。如果欄位值包含逗號,可以改用 TSV 檔案。 TSV 與 CSV 同屬純文字格式,筆數上限同樣取決於開啟的軟體,格式本身無限制。 === 3. Excel 檔案=== Excel 檔案:常見的檔案類型,但是儲存格文字長度與欄位數量都有上限:單一儲存格內的文字不能超過 32,767 字,而欄位數上限是 16,384 欄 <ref>Microsoft Support — Excel specifications and limits: https://support.microsoft.com/en-us/office/excel-specifications-and-limits-1672b34d-7043-467e-8e27-269d656771c3</ref>。其次雖然資料筆數理論上限是 1,048,576 筆(= 2²⁰),但如果筆數超過 10 萬筆,電腦操作 Excel 就會頓頓的,反而不方便分析。如果是舊版 Excel(2003 以前)允許的筆數更少,僅 65,536 筆(= 2¹⁶)× 256 欄。<ref>[Did You Know] Microsoft Excel has a Limit of Maximum 1,048,576 Rows and 16,384 Columns – AskVG https://www.askvg.com/did-you-know-microsoft-excel-has-a-limit-of-maximum-1048576-rows-and-16384-columns/</ref><ref>[https://superuser.com/questions/366468/what-is-the-maximum-allowed-rows-in-a-microsoft-excel-xls-or-xlsx What is the maximum allowed rows in a Microsoft Excel .xls or .xlsx - Super User]</ref> 常見問題是 Excel 雖然方便但經常會把長數字(例如:訂單編號)自動轉成科學記號顯示<ref>[https://errerrors.blogspot.com/2023/04/how-to-fix-rounding-after-15-digits-on-excel.html 解決 Excel 長數字的最後一位歸零或出現科學記號的問題]</ref>,或把特定字串(如 1-2、MAR3)誤判為日期<ref>[https://www.techbang.com/posts/110723-excel-human-genome Excel功能出包,迫使科學家必須重新命名人類基因!現在這個Bug被修復了 | T客邦]</ref>,造成資料遺失或資料錯誤。 === 4. JSON 檔案 === JSON 檔案:適合複雜格式或者說自由風格的欄位定義。曾經拿到包含多筆資料,約 250 MB 檔案大小的 JSON 檔案。因為發生檔案讀取錯誤,需要額外切割檔案內容。 JSON 格式本身沒有筆數上限,瓶頸是讀取時必須將整個檔案載入記憶體,因此檔案愈大愈容易發生記憶體不足的錯誤。<ref>Quora — What is the practical limit on the size of a JSON message?: https://www.quora.com/What-is-the-practical-limit-on-the-size-of-a-JSON-message-for-an-internet-application</ref> 實務上建議不要將多筆資料寫在 JSON,而改成 JSONL,也就是 JSON 加上換行符號區別多筆資料。適合使用程式用串流方式逐行讀取,而不致於發生記憶體錯誤。 === 5. SQLite 或 Parquet 檔案 === SQLite 或 Parquet 檔案:當資料量超過 Excel 筆數上限,可以考慮使用這兩種格式。 SQLite 每張資料表的理論筆數上限是 2⁶⁴ 筆(約 1.8 × 10¹⁹),但這個數字實際上不可能達到,因為資料庫檔案大小上限 281 TB 會先被遇到。在最大資料庫容量下,可儲存的筆數約為 2 × 10¹³ 筆(前提是沒有索引且每筆資料極小)。<ref>SQLite 官方文件 — Implementation Limits For SQLite: https://sqlite.org/limits.html</ref> Parquet 沒有硬性的筆數上限。格式本身以 Row Group 為單位儲存資料。Row Group 是 Parquet 檔案內部的水平分割單位,每個 Row Group 包含一段連續的資料列,以欄位為單位分開存放——例如一個有 100 萬筆、10 個欄位的資料集,在一個 Row Group 裡會被切成 10 段欄位資料分別儲存,而非逐列存放。這樣的設計讓查詢時只需讀取需要的欄位,不必掃描整列,大幅提升讀取效率。每個 Row Group 預設上限為 100 萬筆,但一個檔案可以包含任意數量的 Row Group,因此整個檔案的筆數沒有理論上限 <ref>Apache arrow-rs GitHub issue #5797 — "Row groups are limited to 1M rows by default": https://github.com/apache/arrow-rs/issues/5797</ref>。實務上已有人成功寫入 5 億~ 10 億筆資料<ref>Andy Cutler — 10 Billion Rows: Parquet File Size and Distribution When using CETAS: https://www.serverlesssql.com/row-size-and-parquet-file-distribution/</ref>,瓶頸通常是硬碟空間,而非格式本身。 === 6. SQL 檔案 === SQL 檔案:關聯式資料庫的匯出格式,內容為多列的 SQL 語法(如 {{kbd | key=<nowiki>INSERT INTO ...</nowiki>}}),可直接匯入至資料庫。 SQL 檔案本身沒有筆數上限,格式本身只是純文字,限制同樣來自開啟或匯入它的工具。 常見問題是 * (1) 檔案過大:大量資料匯出後動輒數 GB,用文字編輯器開啟會導致當機或無回應。 * (2) 跨資料庫相容性:不同資料庫引擎(如 MySQL、PostgreSQL、SQLite)的 SQL 語法有差異,從 A 引擎匯出的 .sql 檔案,未必能直接匯入另一個引擎。可參考 [[排除_MySQL_技術疑難問題#從_MySQL_資料轉移至_MSSQL | 從_MySQL_資料轉移至_MSSQL]] 如果只需要搬移資料而非還原完整資料庫結構,建議改用 CSV 或 Parquet,避免上述相容性問題。 == References == <references /> {{Template:Data factory flow}} [[Category: Software]] [[Category: Spreadsheet]] [[Category: MySQL]] [[Category: Data Science]] [[Category: Revised with LLMs]]
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Data factory flow
(
edit
)
Template:Kbd
(
edit
)
Template:LanguageSwitcher
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
Tools
What links here
Related changes
Special pages
Page information