python将DataFrame存入parquet文件中

代码

import pandas as pd
import pyarrow.parquet as pq
import pyarrow as pa

out_file = 'test.parquet'
array = [1, 2, 3, 4]

df = pd.DataFrame(array)
# Create a parquet table from your dataframe
table = pa.Table.from_pandas(df)
# Write direct to your parquet file
pq.write_table(table, out_file)

# write to this dir and auto name the parquet file
out_path = './database/'
pq.write_to_dataset(table, root_path = out_path)

结果示例

pq.write_table

在这里插入图片描述

pq.write_to_dataset 

在这里插入图片描述

你可能感兴趣的:(人工智能,python,开发语言,pandas)