V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
scalaer
V2EX  ›  Python

30M 左右的 parquet 文件, 转成 pandas 的 dataframe 存 mysql, 直接耗完 6 个 g 的内存?

  •  
  •   scalaer · 2019-01-18 14:36:23 +08:00 · 1294 次点击
    这是一个创建于 1896 天前的主题,其中的信息可能已经有所发展或是发生改变。

    python 代码

    from pyarrow import parquet as pq
    
    
    fs = s3fs.S3FileSystem(...)
    
    path = ['s3a://.....']
    
    r = pq.ParquetDataset(_path, filesystem=fs)
    df = r.read().to_pandas()
    df.to_sql(....)
    

    相关的日志

    Jan 18 14:18:33  kernel: Out of memory: Kill process 3342 (python3) score 842 or sacrifice child
    Jan 18 14:18:33  kernel: Killed process 3342 (python3) total-vm:7950428kB, anon-rss:6945048kB, file-rss:0kB, shmem-rss:0kB
    
    1 条回复    2019-01-18 14:49:24 +08:00
    scalaer
        1
    scalaer  
    OP
       2019-01-18 14:49:24 +08:00
    漏了点处理
    df['_time'] = df['time'].apply(lambda x: parse(x[:11] + " " + x[12:]).strftime("%Y-%m-%d %H:%M:%S"))
    df['bytes'] = df['request_size'] + df['response_size']
    df['bytes'] = df['bytes'].astype(int)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5665 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 95ms · UTC 06:30 · PVG 14:30 · LAX 23:30 · JFK 02:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.