Jor*_*dan 4 python types seaborn python-polars
有人使用 Seaborn 的 Polars 数据框来绘制图表吗?我一直在 Kaggle 上使用 Pandas 编写笔记本,我想将其重构为 Polars。
我正在使用的数据框如下所示:
| 乘客 ID (i64) | 幸存 (i64) | P级 (i64) | 名称(字符串) | ... | 门票(str) | 票价 (f64) | 客舱(str) | 已登船 (str) | 年龄 (f64) |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 3 | 你的名字在这里 | ... | A/5 21171 | 7.25 | 无效的 | S | 24 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
Kaggle 让我使用以下代码制作直方图:
g = sns.FacetGrid(train_df, col='Survived')
g.map(plt.hist, 'Age', bins=20)
Run Code Online (Sandbox Code Playgroud)
当我运行这两行时,出现以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/seaborn/axisgrid.py", line 678, in map
for (row_i, col_j, hue_k), data_ijk in self.facet_data():
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/seaborn/axisgrid.py", line 632, in facet_data
data_ijk = data[row & col & hue & self._not_na]
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/polars/internals/series/series.py", line 906, in __array_ufunc__
args.append(arg.view(ignore_nulls=True))
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/polars/internals/series/series.py", line 2680, in view
ptr_type = dtype_to_ctype(self.dtype)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/polars/datatypes.py", line 550, in dtype_to_ctype
raise NotImplementedError(
NotImplementedError: Conversion of polars data type <class 'polars.datatypes.Boolean'> to C-type not implemented.
Run Code Online (Sandbox Code Playgroud)
我的数据框中没有任何布尔数据类型,因此我不确定如何处理此错误。有任何想法吗?
Seaborn 不接受 Polars 数据帧作为输入。你只需要使用to_pandas()
所以g = sns.FacetGrid(train_df, col='Survived')改为
g = sns.FacetGrid(train_df.to_pandas(), col='Survived')
Run Code Online (Sandbox Code Playgroud)