DEV Community

Derrick Sherrill for WayScript

Posted on

Programmatically Write CSV Files using Pandas, Python, and WayScript

Introduction

Working with WayScript helps you automate simple tasks while you can focus on the important work.

Today, we’ll learn to use Python to programmatically write CSV files with pandas.

Prerequisites

No prerequisites but some content you might find helpful:

Time Trigger

To make the script running, we’ll simply use a Time Trigger.

Add it as a Trigger and choose whatever time suits you best.

Adding the Trigger

Requests

WayScript provides a Requests module to easily make requests without having to write a single line of code. Add it as a new step.

Adding the module

We’ll make requests to Star Wars API. We’ll fetch all the planets of the Star Wars Universe using this endpoint. https://swapi.dev/api/planets/

Configuring the module

Once it’s done we can write the Python Script to write the JSON data into a CSV file.

Python

WayScript also provides a Python module to execute python scripts in our workflow. Add it as a new step.

Adding the Python module

Once it’s added, we can write the script.

Writing the script

If you run the script, you’ll notice a new file in the project directory. Well, it’s our CSV file.

File in the directory

Well, here’s the content.

Content of the CSV file

Conclusion

Questions about this script or anything else? Join our Discord. We're always around to help. If you want to work with the full script template, just find it here.

Top comments (0)