Skip to content
Advertisement

Write multi-line data to CSV in python

I’m a noob trying to learn Python by scraping a website to track fund parameters. So far, the following code isolates and shows the data that I need,

JavaScript

This code shows the following data:

JavaScript

How can I write this data to a CSV with the following headers?

JavaScript

This is for a single fund and I need to get this data for about 100 more funds. I will experiment more and any issues there are perhaps for another Q at a later time :) Since I’m a newbie, any other improvements and why you’d do those would also be appreciated!

Advertisement

Answer

Assemble the data for each fund in a list to easily write it out in CSV format using Python’s builtin csv module:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement