繁体   English   中英

为什么 xlwings 不会从这个 dataframe 复制超过 8 行?

[英]Any reason why xlwings will not copy more than 8 lines from this dataframe?

我刚刚开始学习 xlwings 并将信息从 python 复制到 excel。 但是,这不会复制所有信息。 xlwings 的任何专家都知道为什么并且可以解决此问题吗? 公司信息中有 154 行,但只有 8 行被复制到 excel 然后停止。 在 jupyter 或 IDEL 或 VS 中运行时,信息可见但不会复制到 excel。 历史价格数据(sheet2)工作得很好。 谢谢

import time
import pandas as pd
import numpy as np
import xlwings as xw
import yfinance as yf

stock = yf.Ticker("JPM")

wb  = xw.Book() 

info = stock.info.items()
info = pd.DataFrame(info, columns = ['keys', 'values'])
sheet1 = wb.sheets.add('Co. Info')
sheet1.range('A1').value = info

hist = pd.DataFrame(stock.history(period="max"))
sheet2 = wb.sheets.add('Px Hist')
sheet2.range('A1').value = hist

在 jupyter 或 IDLE 中运行时,sheet1 或“Co. Info”中的字典“info”的 output 如下所示:

dict_items([('zip', '95014'), ('sector', 'Technology'),....... 
 ('preMarketPrice', 175.84), ('logo_url', 'https://logo.clearbit.com/apple.com')])

仔细查看 pandas dataframe info的第 8 行。 values8行的单元格包含一个空列表[] 似乎 xlwings 无法处理将具有 pandas dataframe 的空列表的单元格复制到 excel 表。 我会说这是一个错误。 如果在将info复制到 excel 表之前删除空列表,则可以正常工作:

import time
import pandas as pd
import numpy as np
import xlwings as xw
import yfinance as yf

stock = yf.Ticker("JPM")

wb  = xw.Book()

info = stock.info.items()
info = pd.DataFrame(info, columns = ['keys', 'values'])
info.drop(8, axis=0, inplace=True) # Remove row 8.
sheet1 = wb.sheets.add('Co. Info')
sheet1.range('A1').value = info

hist = pd.DataFrame(stock.history(period="max"))
sheet2 = wb.sheets.add('Px Hist')
sheet2.range('A1').value = hist

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM