Arthur Camberlein >> SEO & Data articles >> How to save a .parquet file in Python?

How to save a .parquet file in Python?

How to save a .parquet file in Python?

To save a .parquet file with Python, you can use the pandas library, which provides a convenient way to read and write data in a variety of formats, including Parquet.

Let me share with you an example:

```Python import pandas as pd

create a sample DataFrame

data = {'name': ['Alice', 'Bob', 'Charlie'],
        'age': [25, 30, 35],
        'city': ['New York', 'San Francisco', 'Seattle']}
df = pd.DataFrame(data)

Save the DataFrame as a Parquet file

df.to_parquet('example.parquet')

In this example, I first created a sample DataFrame using a Python dictionary an calling it data

Then use the to_parquet() method -- as part of pandas -- to save the DataFrame as a Parquet file.

Note: The file will be saved in the current working directory with the name example.parquet.

  1. you can change the name of the file from example to my_data_frame
  2. you can change the directory to save this file by adding folder/subfolder/example.parquet
  3. you can also change the directory using os
Back to blog

Blog post taggues in:Data, Python, Tips

Related blog posts: