V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
XiaoCilang
V2EX  ›  Python

请教个问题,将 excel 中的数据生成折线图并保存在 excel 中,要求手动打开 excel 时还可以操作该折线图

  •  
  •   XiaoCilang · 2022-07-10 18:57:11 +08:00 · 1593 次点击
    这是一个创建于 661 天前的主题,其中的信息可能已经有所发展或是发生改变。

    各位大佬,我现在需要根据 excel 中的某些数据生成折线图,然后将折线图保存到该 sheet 中。网上的方式都是 save 到本地或 io 里,保存成一个图片,再插入到 excel 。但是我的需求是插入到 excel 的图表还能操作,比如显示数据标签,数据表。请教下该怎么操作?

    比如:

    import pandas as pd

    df = pd.read_excel(".SS.xlsx")

    df.plot(x=["test-row"], y=["test_col"])

    plt.save("test.jpg")

    plt.close()

    worksheet = writer.sheets["sheet"]

    worksheet.insert_image("C2", r".\test.jpg")

    3 条回复    2022-07-11 15:03:02 +08:00
    TimePPT
        1
    TimePPT  
       2022-07-10 19:21:49 +08:00 via Android   ❤️ 1
    试试 openpyxl ?
    XiaoCilang
        2
    XiaoCilang  
    OP
       2022-07-10 19:39:18 +08:00
    #1
    @TimePPT 感谢感谢。忘了说了最好与 pandas 的兼容性好一点,之前的数据处理比较麻烦。openpyxl 好像支持 DataFrame 对象,我研究下
    maybedk
        3
    maybedk  
       2022-07-11 15:03:02 +08:00
    试试 xlwings 吧,调用的是 excel 的 api 。基本就是在用 Python 写 vbs 宏。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   978 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 23:13 · PVG 07:13 · LAX 16:13 · JFK 19:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.