INTERNET_CSV
Overview
The INTERNET_CSV
function allows you to import data from any public CSV file on the internet directly into Excel. By providing a URL to a CSV file, the function fetches the file, parses its contents, and returns the data as a 2D list (range) suitable for use in Excel formulas. This is meant primarily as an example you can build off of for functions requiring access to data on the internet.
The function automatically prepends the URL with https://cors.boardflare.com/
before fetching the file. This proxies the request and appends the CORS headers required by the browser.
Usage
To use the INTERNET_CSV
function in Excel, enter it as a formula in a cell, specifying the direct URL to the CSV file you want to import:
=INTERNET_CSV(url)
url
(string, required): The direct URL to the CSV file you want to import.
The function returns a 2D list containing the parsed CSV data (each row is a list of strings), or an error message as a string if an exception occurs.
Examples
Example 1: Importing Zillow Market Heat Index Data
In Excel:
=INTERNET_CSV("https://files.zillowstatic.com/research/public_csvs/market_temp_index/Metro_market_temp_index_uc_sfrcondo_month.csv?t=1746621339")
Expected output:
RegionID | SizeRank | RegionName | RegionType | StateName | 2018-01-31 | 2018-02-28 |
---|---|---|---|---|---|---|
102001 | 0 | United States | country | 50 | 50 | |
394913 | 1 | New York, NY | msa | NY | 52 | 52 |
753899 | 2 | Los Angeles, CA | msa | CA | 69 | 67 |
394463 | 3 | Chicago, IL | msa | IL | 48 | 49 |
Example 2: Importing Zillow New Construction Sales Data
In Excel:
=INTERNET_CSV("https://files.zillowstatic.com/research/public_csvs/new_con_sales_count_raw/Metro_new_con_sales_count_raw_uc_sfrcondo_month.csv?t=1746621339")
Expected output:
RegionID | SizeRank | RegionName | RegionType | StateName | 2018-01-31 | 2018-02-28 |
---|---|---|---|---|---|---|
102001 | 0 | United States | country | 34508 | 33782 | |
394913 | 1 | New York, NY | msa | NY | 532 | 447 |
753899 | 2 | Los Angeles, CA | msa | CA | 333 | 398 |
394463 | 3 | Chicago, IL | msa | IL | 288 | 255 |
Python Code
import csv
import io
import requests
def internet_csv(url):
"""
Fetches a CSV file from the internet (with CORS proxy) and returns its contents as a 2D list.
Args:
url (str): The direct URL to the CSV file.
Returns:
list[list[str]]: 2D list containing the parsed CSV data. Each row is a list of strings.
str: Error message if an exception occurs.
This example function is provided as-is without any representation of accuracy.
"""
if not isinstance(url, str) or not url.strip():
return "Error: A non-empty URL string must be provided."
cors_url = f"https://cors.boardflare.com/{url}"
try:
response = requests.get(cors_url)
response.raise_for_status()
content = response.text
reader = csv.reader(io.StringIO(content))
data = [row for row in reader]
if not data:
return "Error: CSV file is empty or could not be parsed."
max_len = max(len(row) for row in data)
padded_data = [row + [""] * (max_len - len(row)) for row in data]
return padded_data
except Exception as e:
return f"Error: Failed to fetch or parse CSV: {e}"
Live Notebook
Edit this function in a live notebook .