Parquet ファイル、これまであんまり向き合ってこなかったので、少し向き合う。
vim で開けない...かなしい...。
parquet-cli
parquet でぐぐると、parquet-tools 使おうみたいな記事がよく出てくるが、2022年8月現在だともう更新されていないので、代わりに parquet-cli というのを使う。
Mac の場合
$ brew install parquet-cli
で、OK
$ /opt/homebrew/Cellar/parquet-cli/1.12.3/bin/parquet
にあるので、適当に path を通しておきましょう。
$ parquet meta foobar.parquet
で meta データを見たりできる。
詳細は help で
$ parquet help Usage: parquet [options] [command] [command options] Options: -v, --verbose, --debug Print extra debugging information Commands: help Retrieves details on the functions of other commands meta Print a Parquet file's metadata pages Print page summaries for a Parquet file dictionary Print dictionaries for a Parquet column check-stats Check Parquet files for corrupt page and column stats (PARQUET-251) schema Print the Avro schema for a file csv-schema Build a schema from a CSV data sample convert-csv Create a file from CSV data convert Create a Parquet file from a data file to-avro Create an Avro file from a data file cat Print the first N records from a file head Print the first N records from a file column-index Prints the column and offset indexes of a Parquet file column-size Print the column sizes of a parquet file prune Prune column(s) in a Parquet file and save it to a new file. The columns left are not changed. trans-compression Translate the compression from one to another (It doesn't support bloom filter feature yet). masking Replace columns with masked values and write to a new Parquet file footer Print the Parquet file footer in json format Examples: # print information for meta parquet help meta See 'parquet help <command>' for more information on a specific command.
pandas で扱う
pandas で Parquet ファイル 扱うことができる
pip で必要なものをそろえる
$ pip install pandas pyarrow fastparquet
例えば csv にしたい場合はこういう感じ(カレントディレクトリに、foobar.parquet
がある想定)
$ python3 Python 3.10.4 (main, May 25 2022, 11:41:04) [Clang 13.1.6 (clang-1316.0.21.2.3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> >>> >>> import pandas as pd >>> df = pd.read_parquet('foobar.parquet') >>> df.to_csv('foobar.csv')
これから仲良くしていこう...。