Seaborn 代码 Anscombe 的四重奏不起作用

问题描述 投票:0回答:1

Seaborn 代码不起作用。 我使用 jupyterlite 来执行 Seaborn python 代码。

首先,我通过以下方式导入seaborn: import piplite await piplite.install('seaborn') import matplotlib.pyplot as plt import seaborn as sn %matplotlib inline

但是当我插入如下所示的 Seaborn 代码时,它会显示许多我还不明白的错误:

代码链接

问题:

the problem that I face但是我在 Google Colab 中插入这段代码,效果很好:

google colab

python jupyter-notebook google-colaboratory jupyter-lab
1个回答
0
投票

问题步骤与以下内容相关:

# Load the example dataset for Anscombe's quartet df = sns.load_dataset("anscombe")

您需要将行 
df = sns.load_dataset("anscombe")

替换为以下内容:

url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/anscombe.csv' # based on [Data repository for seaborn examples](https://github.com/mwaskom/seaborn-data)
from pyodide.http import open_url
import pandas
df = pandas.read_csv(open_url(url))

这是基于使用 
open_url()

中的

pyodide.http
,请参阅
here
了解更多示例。

替代 pyfetch 并分配获得的字符串

如果您见过 pyfetch,这也可以替代基于

John Hanley 的帖子

sns.load_dataset()
行,该行使用 pyfetch 获取 CSV 数据。代码进一步注释: # GET text at URL via pyfetch based on John Hanley's https://www.jhanley.com/blog/pyscript-loading-python-code-in-the-browser/ url = 'https://raw.githubusercontent.com/mwaskom/seaborn-data/master/anscombe.csv' # based on [Data repository for seaborn examples](https://github.com/mwaskom/seaborn-data) from pyodide.http import pyfetch response = await pyfetch(url) content = (await response.bytes()).decode('utf-8') # READ in string to dataframe based on [farmOS + JupyterLite: Import a CSV of Animals](https://gist.github.com/symbioquine/7641a2ab258726347ec937e8ea02a167) import io import pandas df = pandas.read_csv(io.StringIO(content))

© www.soinside.com 2019 - 2024. All rights reserved.