DEV Community

Derrick Sherrill for WayScript

Posted on

1 1

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.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay