推荐学习书目
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
MainHanzo
V2EX  ›  Python

parquet 格式转换法案

  •  
  •   MainHanzo · Apr 9, 2020 · 3003 views
    This topic created in 2236 days ago, the information mentioned may be changed or developed.
    组里有一些 parquet 希望可以转换格式成 csv 这样的格式,方便人阅读。
    parquet 内部有比较复杂的数据结构, 比如 array of map, array of structs.
    尝试过用 pandas 读取 parquet,直接返回 pyarrow not implemented error,原因是 pandas 会调用 pyarrow 这个模块进行读取. 上网发现读取复杂格式的这个 feature 在 pyarrow 的 jira 里躺了 3 年了。

    我尝试用 spark 直接读取成 spark dataframe, 然后尝试用 spark dataframe 直接转 csv, 也失败了,原因是 csv 不支持 array 。

    总结下有这么几个难点:
    1. 无法读取,pandas 读不了,spark 能读但是其实不符合我们组的要求,他们希望做那种只有 jre 环境就能跑的,或者整个 exe
    2. 无法输出,csv 不支持 array,不能转化的时候把所有数据全处理成 string 再输出吧?这个可能很费时? 我没尝试过但感觉不是好方法

    求指点!
    2 replies    2020-04-10 21:03:39 +08:00
    cassidyhere
        1
    cassidyhere  
       Apr 10, 2020
    1.最新的 pyarrow 是支持 nested data 的: https://github.com/apache/arrow/pull/6751/files
    2.这时 pandas dataframe 转 csv 没问题:
    s = StringIO()
    df = pd.DataFrame({'c1': [[1, 2]], 'c2': [{'k': 'v'}]})
    df.to_csv(s, index=False)
    s.seek(0)
    s.read() # 'c1,c2\r\n"[1, 2]",{\'k\': \'v\'}\r\n'
    MainHanzo
        2
    MainHanzo  
    OP
       Apr 10, 2020
    @cassidyhere 谢谢很有用的信息。 再问个问题,有本地 build arrow 的 guide 吗, 我没找到, 不知道怎么 build from source 谢谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3509 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 11:15 · PVG 19:15 · LAX 04:15 · JFK 07:15
    ♥ Do have faith in what you're doing.