推荐学习书目
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 · Jul 10, 2022 · 2207 views
    This topic created in 1415 days ago, the information mentioned may be changed or developed.

    各位大佬,我现在需要根据 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 replies    2022-07-11 15:03:02 +08:00
    TimePPT
        1
    TimePPT  
    PRO
       Jul 10, 2022 via Android   ❤️ 1
    试试 openpyxl ?
    XiaoCilang
        2
    XiaoCilang  
    OP
       Jul 10, 2022
    #1
    @TimePPT 感谢感谢。忘了说了最好与 pandas 的兼容性好一点,之前的数据处理比较麻烦。openpyxl 好像支持 DataFrame 对象,我研究下
    maybedk
        3
    maybedk  
       Jul 11, 2022
    试试 xlwings 吧,调用的是 excel 的 api 。基本就是在用 Python 写 vbs 宏。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5195 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 01:13 · PVG 09:13 · LAX 18:13 · JFK 21:13
    ♥ Do have faith in what you're doing.