Created
April 15, 2022 09:17
-
-
Save ashutoshkrris/f6917b17fdbeb2ec2a539cdceaa2d8f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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