【发布时间】:2021-04-02 14:11:07
【问题描述】:
该文件应该有数千行。 但是在下面使用它只会返回数据框中的前几行
文件 https://www.hkex.com.hk/eng/services/trading/securities/securitieslists/ListOfSecurities.xlsx
失败的例子
import pandas as pd
url = 'https://www.hkex.com.hk/eng/services/trading/securities/securitieslists/ListOfSecurities.xlsx'
df = pd.read_excel(url, engine='openpyxl', header=2, usecols='A:D', verbose=True)
print(df.shape)
# output - only 5 rows
Reading sheet 0
(5, 4)
工作示例
同一个文件。先下载,在Excel中打开,修改文本并保存(没有改变格式并保留xlsx),然后使用read_excel()从文件中打开
url = 'https://www.hkex.com.hk/eng/services/trading/securities/securitieslists/ListOfSecurities.xlsx'
path = os.path.join(os.path.dirname(__file__), 'download')
wget.download(url, out=path)
file = os.path.join(path, 'ListOfSecurities.xlsx')
# open to edit and then save in Excel
df = pd.read_excel(file, engine='openpyxl', header=2, usecols='A:D', verbose=True)
print(df.shape)
# output
Reading sheet 0
(17490, 4)
【问题讨论】:
-
这个问题可能是由正在使用的数据引起的。您应该包含一些示例数据,以便帮助人员复制问题。
-
下载并注意到同样的问题。形状 (5, 4)。数据格式问题。 “Spread Table”和“Board Lot”列问题
-
但这仍然是有效的 excel 格式。所以在这里寻找解决方案
标签: python excel pandas openpyxl