javascript-使用PyScript在Web中显示数据帧
我在 pyhton 中创建了一个简单的数据框,我想使用PyScript在 Web 中显示它。
下面是我的脚本web.py,它在访问我的 Onedrive 帐户上的测试数据时可以完美运行。
import pandas as pd
url_xl = "https://onedrive.live.com/download?cid=E29C174708A82470&resid=E29C174708A82470%211239&authkey=AAFSfw2ykxOwRr4"
xl = pd.read_excel(url_xl,sheet_name='Sheet1')
print(xl)
web.py - Output:
col1 col2 col3 col4 col5
0 A A A A A
1 B B B B B
2 C C C C C
但是,当我合并上述脚本以在 HTML Script/PyScript 中调用它时。
HTML/PyScript
<html>
<head>
<title> test </title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- pandas
</py-env>
</head>
<body>
<py-script src='./web.py'>
pyscript.write('data',xl.to_html())
</py-script>
</body>
<p id="data"></p>
</html>
我收到了这个错误
JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 429, in eval_code .run(globals, locals) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 300, in run coroutine = eval(self.code, globals, locals) File "", line 4, in File "/lib/python3.10/site-packages/pandas/util/_decorators.py", line 311, in wrapper return func(*args, **kwargs) File "/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 457, in read_excel io = ExcelFile(io, storage_options=storage_options, engine=engine) File "/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 1376, in __init__ ext = inspect_excel_format( File "/lib/python3.10/site-packages/pandas/io/excel/_base.py", line 1250, in inspect_excel_format with get_handle( File "/lib/python3.10/site-packages/pandas/io/common.py", line 670, in get_handle ioargs = _get_filepath_or_buffer( File "/lib/python3.10/site-packages/pandas/io/common.py", line 339, in _get_filepath_or_buffer with urlopen(req_info) as req: File "/lib/python3.10/site-packages/pandas/io/common.py", line 239, in urlopen return urllib.request.urlopen(*args, **kwargs) File "/lib/python3.10/urllib/request.py", line 216, in urlopen return opener.open(url, data, timeout) File "/lib/python3.10/urllib/request.py", line 519, in open response = self._open(req, data) File "/lib/python3.10/urllib/request.py", line 541, in _open return self._call_chain(self.handle_open, 'unknown', File "/lib/python3.10/urllib/request.py", line 496, in _call_chain result = func(*args) File "/lib/python3.10/urllib/request.py", line 1419, in unknown_open raise URLError('unknown url type: %s' % type) urllib.error.URLError: )
使用检查
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading base.ts:128:79 'setAttribute') at PyScript.evaluate (base.ts:128:79)