To start off, you likely already have a CSV document you're looking to process with python. To accomplish this with WayScript we just a CSV module. A module in wayscript can be thought of as a "building block" of a script. We'll use the CSV module to accomplish a CSV action.
In this tutorial, I'm just using public data I found online about companies and their funding information. We can upload this CSV file and configure the rest of the settings of the csv module as seen below:
Whenever we're reading in any type of spreadsheet styled data, we'll need to import the columns we want to work with. Whenever we import these columns, they will become variables within our script that we can use throughout the workflow.
After we've read in the data we want to work with from our CSV document, we can use python programming to do any type of processing we want to do with it. We'll drag in a python module below the csv module:
This gives us access to a full python editor in which we can input our own python code. Let's do a simple operation in python and then return the result.
amounts = variables['raised_amount']
new_list = [int(i)*2 for i in amounts]
variables['new_list'] = new_list
The variables dictionary that we're referencing here is how we manage variables in wayscript inside of the python editor. We can access and assign new variables to our script (in wayscript) in this way.
Once we've done the operations we want to inside of python, we can write that information back to csv. We can do this by using a loop operation.
The items that we want to loop over, are each of the list values that we want to write to CSV.
With each of these new iterated values, we can write them to CSV using a csv module inside the loop.
As always, if you have any questions please reach out to us on our discord and we would be happy to help. If you want to view this completed script, you can find it here.
Posted on May 26 by: