Hey @alonisser
One simple and effective approach is to convert the PySpark DataFrame to a Pandas DataFrame and save it directly to a Unity Catalog Volume with a custom filename.
* You can use widgets to dynamically set values like the client name, and encapsulate the logic in a reusable function to streamline your workflow.
Hereโs a minimal example:
import pandas as pd
# Example: replace with dbutils.widgets.get("client_name") if using widgets
client = "001"
section = "transactions"
# Convert Spark DataFrame to Pandas
df_1 = df.toPandas()
# Define a custom filename
filename = f"{client}_{section}.csv"
# Define the target Volume path
volume_path = f"/Volumes/<catalog>/<schema>/<volume_name>/{filename}"
# Export the file as CSV to the Volume
df_1.to_csv(volume_path, index=False)
print(f"File saved to: {volume_path}")
Hope this helps, ๐
Isi