Created
November 1, 2020 13:49
-
-
Save julian-klode/b0e359324e64e519a8fceddb6cdb8cac 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 | |
import difflib | |
with open("a1jx52.csv") as ftse: | |
ftse_list = list(csv.reader(ftse)) | |
with open("IUSN_holdings.csv") as small: | |
small_list = list(csv.reader(small)) | |
def clean(s): | |
for c in ". ,": | |
s=s.replace(c, "") | |
return s.lower() | |
ftse = {clean(s[0]): s for s in ftse_list if len(s) > 5} | |
small = {clean(s[1]): s for s in small_list if len(s) > 5} | |
ftse_names = set(ftse.keys()) | |
small_names = set(small.keys()) | |
rows = [["Name", "MSCI World Small Cap %", "FTSE All World %","Market Cap (FTSE)", "MCap (MSCI)"]] | |
for i in sorted(ftse_names & small_names, key=lambda n: float(small[n][3].replace(",", ".")), reverse=True): | |
rows.append([ftse[i][0], small[i][3]+"%", ftse[i][1].replace("\xa0",""), ftse[i][4], small[i][6]]) | |
import tabulate | |
print(tabulate.tabulate(rows[1:], headers=rows[0], tablefmt="pipe")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment