Hmmm... the download from your site is tricky. I cannot see why it won't work with open_url
when your site behaves the same as https://s3.eu-west-1.amazonaws.com/assets.holoviews.org/data/nyc_taxi_wide.csv
when I access each in m browser. And https://s3.eu-west-1.amazonaws.com/assets.holoviews.org/data/nyc_taxi_wide.csv
works with open_url
. So that rules out it being any Cross Origin Resource problem (CORS).
And it is even odder since as MuthuSankaraNarayanan Valliamm points out data=pd.read_csv('https://people.math.sc.edu/Burkardt/datasets/csv/turtles.csv')
works when run in a typical, full Python kernel.
And the following based on here works in a typical Python kernel, too:
# based on https://stackoverflow.com/a/35371451/8508004
import csv
import requests
CSV_URL = 'https://people.math.sc.edu/Burkardt/datasets/csv/turtles.csv'
with requests.Session() as s:
download = s.get(CSV_URL)
decoded_content = download.content.decode('utf-8')
print(decoded_content)
cr = csv.reader(decoded_content.splitlines(), delimiter=',')
my_list = list(cr)
for row in my_list:
#print(row)
pass
Maybe someone will point out how to make your source work with pyscript? For now I moved your data to GitHub.
Below is an example that links to the actual CSV data URL where I moved your data to GitHub.
Solution: use open_url
to get CSV
Often the Pyscript demonstrations include more useful examples than the higher level guides, such as https://docs.pyscript.net/latest/guides/http-requests.html . Getting a CSV boils down to df = pd.read_csv(open_url(url))
as demonstrated
They have an example getting a CSV you can adapt
Importantly for you, there is an offered example called NYC Taxi Data Panel DeckGL Demo that includes getting data as a CSV file among those listed on the Pyscript demos page. It is found presently under the 'Visualizations & Dashboards' section there, which is way at the bottom presently:
- link to 'NYC Taxi Data Panel DeckGL Demo' pyscript example running served on web: here
- link to the code for 'NYC Taxi Data Panel DeckGL Demo' pyscript example on Github: here
Adapting your code to that example to focus on getting the CSV:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="theme-color" content="#0072b5" />
<meta name="name" content="CSV Getting Demo adapted from PyScript/Panel DeckGL Demo" />
<title>CSV Getting Demo</title>
<link rel="icon" type="image/x-icon" href="./favicon.png" />
<link
rel="stylesheet"
href="https://pyscript.net/latest/pyscript.css"
/>
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
<link rel="stylesheet" href="https://pyscript.net/examples/assets/css/examples.css" />
</head>
<body>
<div id="pandas-output" hidden>
<h3>Output</h3>
<div id="pandas-output-inner"></div>
</div>
<py-tutor>
<py-config>
packages = [
"numpy",
"pandas",
"jinja2"
]
plugins = [
"https://pyscript.net/latest/plugins/python/py_tutor.py"
]
</py-config>
<py-script>
import pandas as pd
from pyodide.http import open_url
url = 'https://raw.githubusercontent.com/fomightez/pyscript_test/main/turtles.csv'
df = pd.read_csv(open_url(url))
Element("pandas-output").element.style.display = "block"
display (df.head().style.format(precision=2), target="pandas-output-inner", append="False")
</py-script>
</py-tutor>
</section>
</body>
</html>
You can run that right here by clicking the 'Run code snippet' button. Because of the small area and the dataframe being displayed in the top of a section, I found I needed to then click on 'Full page' view option that will then come up on the right side in order to see the dataframe well. You can get back to the post by clicking on 'Close' in the upper right from the full page view.)