?? 作者:韓信子@ShowMeAI
?? 資料分析實戰系列:https://www.showmeai.tech/tutorials/40
?? 本文地址:https://www.showmeai.tech/article-detail/409
?? 宣告:著作權所有,轉載請聯系平臺與作者并注明出處
?? 收藏ShowMeAI查看更多精彩內容
?? 引言
我們在處理本地存盤的資料時遇到了一些問題,在相對較小的資料集上,讀取-處理-寫入操作可能很舒服,但對于大型 .csv 檔案來說,這些操作非常麻煩,可能會消耗大量時間和資源,
為了解決這個問題,我將介紹兩種檔案型別,它們可以提高您的資料讀寫速度,并壓縮存盤在磁盤上的資料大小:
- ??Parquet
- ??Feather
這兩種檔案型別都具有以下特點:
- 默認情況下可以使用 Python-Pandas 訪問,不過,您可能需要額外安裝 pyarrow 和它的一些擴展,具體取決于您的資料型別,
- 支持基于列的 I/O 管理,這樣,您可以防止在讀取所有資料時臨時使用額外的 RAM,然后洗掉不需要的列,
- 以二進制格式以自己的型別而不是原始格式存盤資料,您最多可以節省 50% 的存盤空間,并且可以在讀寫操作中獲得高達 x100 的加速,
這兩種檔案型別都非常易于使用,更改您當前使用的代碼行即可,讓我們來看看它們!
?? Parquet格式
import pandas as pd
df = pd.read_csv("some_data.csv")
# Saving Parquet files
df.to_parquet("df.parquet")
# Reading Parquet files
df_parq = pd.read_parquet("df.parquet")
?? Feather格式
import pandas as pd
df = pd.read_csv("some_data.csv")
# Saving Feather files
df.to_feather("df.feather")
# Reading Feather files
df_feat = pd.read_feather("df.feather")
?? 總結
在本篇內容中,ShowMeAI給大家介紹了提高讀寫速度的資料格式,如果您不想使用 Excel 原始格式存盤資料,那么建議您使用并行讀取和寫入資料的方法,這樣可以提高資料處理的速度和效率,
參考資料
- ??Parquet
- ??Feather
推薦閱讀
- ?? 資料分析實戰系列:https://www.showmeai.tech/tutorials/40
- ?? 機器學習資料分析實戰系列:https://www.showmeai.tech/tutorials/41
- ?? 深度學習資料分析實戰系列:https://www.showmeai.tech/tutorials/42
- ?? TensorFlow資料分析實戰系列:https://www.showmeai.tech/tutorials/43
- ?? PyTorch資料分析實戰系列:https://www.showmeai.tech/tutorials/44
- ?? NLP實戰資料分析實戰系列:https://www.showmeai.tech/tutorials/45
- ?? CV實戰資料分析實戰系列:https://www.showmeai.tech/tutorials/46
- ?? AI 面試題庫系列:https://www.showmeai.tech/tutorials/48
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/540442.html
標籤:Python
上一篇:day07-功能實作06
