You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kaggle Notebook中Polars绘图依赖hvplot报错的解决咨询

Polars绘图依赖报错的解决思路

1. 确认版本兼容性并重装依赖

  • 直接指定兼容版本安装,执行:!pip install hvplot>=0.9.1 polars>=0.19.0(Polars 0.19及以上版本对hvplot的支持更稳定)
  • 安装完成后重启Kaggle Notebook内核,避免缓存导致的版本不匹配问题

2. 显式导入hvplot并初始化绑定

Polars的plot接口由hvplot注入,需显式导入确保生效,同时提前处理日期列类型避免绘图报错:

import polars as pl
import hvplot.polars  # 显式导入,确保Polars能调用plot方法

polars_etf_prices = pl.read_csv('/kaggle/input/mutual-funds-and-etfs/ETF prices.csv', has_header=True)
# 转换日期列类型为日期格式
polars_etf_prices = polars_etf_prices.with_columns(pl.col('price_date').str.to_date())
polars_etf_prices.plot.line(x='price_date', y='open')

3. 绕过hvplot,改用Matplotlib直接绘图

如果hvplot的依赖问题无法快速解决,可直接用Matplotlib实现绘图需求:

import polars as pl
import matplotlib.pyplot as plt

polars_etf_prices = pl.read_csv('/kaggle/input/mutual-funds-and-etfs/ETF prices.csv', has_header=True)
polars_etf_prices = polars_etf_prices.with_columns(pl.col('price_date').str.to_date())

plt.figure(figsize=(12,6))
plt.plot(polars_etf_prices['price_date'], polars_etf_prices['open'])
plt.xlabel('Price Date')
plt.ylabel('Open Price')
plt.title('ETF Open Prices Over Time')
plt.xticks(rotation=45)
plt.show()

4. 排查环境依赖冲突

  • 执行!pip list | grep -E 'polars|hvplot|holoviews'查看已安装版本,确认是否存在版本冲突
  • 若有冲突,先卸载相关包再重新安装:
    !pip uninstall -y polars hvplot holoviews
    !pip install polars hvplot>=0.9.1
    

内容的提问来源于stack exchange,提问作者DarkBlueSky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 20:50:56