Write Python Data to CSV in your Web Browser
Tags: python, csv, browser, wayscript
Published: 2020-05-26 15:53:46

##Introduction
The ability to automate common tasks, like writing CSV, is a huge benefit of using WayScript. The ability to integrate custom code into these automations, such as python and javascript, makes WayScript shine above the others. Let's take a look at how easy it is to create integrations that easily automate your CSV tasks, while giving you unlimited possibilities on how you can customize it for your own needs.

###Prerequisites
No requirements, but some documentation you may find useful:
[Working with Python](https://docs.wayscript.com/library/modules/python)
[Working with CSV](https://docs.wayscript.com/library/modules/csv)

###Reading in CSV Files
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.

![csv Action pictures](https://cdn.wayscript.com/blog_img/91/1.png)


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:

![csv Action pictures](https://cdn.wayscript.com/blog_img/91/2.png)


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.

###Processing CSV data with Python
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:

![csv Action pictures](https://cdn.wayscript.com/blog_img/91/3.png)

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]
print(new_list[0])
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.

###Writing variables back to csv
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.

![csv Action pictures](https://cdn.wayscript.com/blog_img/91/4.png)


The items that we want to loop over, are each of the list values that we want to write to CSV.

![csv Action pictures](https://cdn.wayscript.com/blog_img/91/5.png)

With each of these new iterated values, we can write them to CSV using a csv module inside the loop.


![csv Action pictures](https://cdn.wayscript.com/blog_img/91/6.png)


###Questions, Feedback?
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](https://wayscript.com/user/derricks/20670).