【发布时间】:2023-01-04 00:05:56
【问题描述】:
我想用 Polars 替换 Pandas,但我无法找到如何在不转换为 Pandas 的情况下将 Polars 与 Plotly 一起使用。我想知道是否有办法将 Pandas 完全排除在流程之外。
考虑以下测试数据:
import polars as pl
import numpy as np
import plotly.express as px
df = pl.DataFrame(
{
"nrs": [1, 2, 3, None, 5],
"names": ["foo", "ham", "spam", "egg", None],
"random": np.random.rand(5),
"groups": ["A", "A", "B", "C", "B"],
}
)
fig = px.bar(df, x='names', y='random')
fig.show()
我希望此代码在 Jupyter 笔记本中显示条形图,但它返回错误:
/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/polars/internals/frame.py:1483: UserWarning: accessing series as Attribute of a DataFrame is deprecated
warnings.warn("accessing series as Attribute of a DataFrame is deprecated")
可以使用 df = df.to_pandas() 将 Polars 数据帧转换为 Pandas 数据帧。然后,它起作用了。但是,是否有另一种更简单、更优雅的解决方案?
【问题讨论】:
标签: python plotly-python python-polars