Skip to content

Instantly share code, notes, and snippets.

@julian-klode
Created November 1, 2020 13:49
Show Gist options
  • Save julian-klode/b0e359324e64e519a8fceddb6cdb8cac to your computer and use it in GitHub Desktop.
Save julian-klode/b0e359324e64e519a8fceddb6cdb8cac to your computer and use it in GitHub Desktop.
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