Skip to content

Instantly share code, notes, and snippets.

@ashutoshkrris
Created April 15, 2022 09:17
Show Gist options
  • Save ashutoshkrris/f6917b17fdbeb2ec2a539cdceaa2d8f7 to your computer and use it in GitHub Desktop.
Save ashutoshkrris/f6917b17fdbeb2ec2a539cdceaa2d8f7 to your computer and use it in GitHub Desktop.
import csv
def write_to_csv(data: dict) -> None:
columns = ['Rank', 'Name', 'Link',
'Total net worth($)', '$ Last change', '$ YTD change', 'Country/Region', 'Industry']
with open(f"top-{TOTAL_PERSONS}-persons.csv", "w", newline="") as csv_file:
writer = csv.DictWriter(csv_file, fieldnames=columns)
writer.writeheader()
for i in range(TOTAL_PERSONS):
temp = {
"Rank": data["ranks"][i],
"Name": data["names"][i],
"Link": f"https://www.bloomberg.com/billionaires/{data['links'][i]}",
"Total net worth($)": data["worths"][i],
"$ Last change": data["last_changes"][i],
"$ YTD change": data["ytds"][i],
"Country/Region": data["countries"][i],
"Industry": data["industries"][i]
}
writer.writerow(temp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment