import pandas as pd from pathlib import Path # Specify the folder path containing parquet files folder_path = "/Users/fredericlegrand/Documents/Code/Python tests/temp/data/chunk-000" # Iterate through all parquet files in the folder for file in Path(folder_path).glob("*.parquet"): # Read parquet file df = pd.read_parquet(file) # Slice the first 6 items from the arrays in "action" and "observation.state" df["action"] = df["action"].apply(lambda x: x[:6]) df["observation.state"] = df["observation.state"].apply(lambda x: x[:6]) # Overwrite the original file with the modified data df.to_parquet(file) print(f"Processed {file.name}") print("All files processed.")