GithubHelp home page GithubHelp logo

optimization-of-pandas-for-large-csv's Introduction

optimization-of-pandas-for-large-CSV

Pandas 是常用的 Python 软件库,可用于数据操作和分析。在进行数据分析时,导入数据(例如pd.read_csv)几乎是必需的,但对于大的CSV,可能会需要占用大量的内存和读取时间,这对于数据分析时如果需要Reloading原始数据的话会非常低效。 Dataquest.io 发布了一篇关于如何优化 pandas 内存占用的教程,仅需进行简单的数据类型转换,就能够将一个棒球比赛数据集的内存占用减少了近 90%,而pandas本身集成上的一些压缩数据类型可以帮助我们快速读取数据。

1. 方法介绍

博客

2.类的使用

step1:导入:from Reduce_fastload import reduce_fastload
step2:实例化:process=reduce_fastload('your path',use_HDF5=True/False,use_feather=True/False)
step3:对原始数据作内存优化:process.reduce_data()
step4:加载优化数据:process_data=process.reload_data()

example

在这里插入图片描述
可以看出,原CSV文件占用内存为616.95MB,优化内存后的占用仅为173.9MB,且相对于原来pd.read_csv的7.7s的loading time,读入优化后的预处理数据文件能很大程度上的加速了读取。

Reference

[1].https://www.kaggle.com/arjanso/reducing-dataframe-memory-size-by-65
[2].https://zhuanlan.zhihu.com/p/56541628
[3].https://blog.csdn.net/weiyongle1996/article/details/78498603

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.