如何从导入的表格中选择特定的列?

问题描述 投票:0回答:2

我正在Google表格中使用以下公式提取一些财务数据:

=TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT,"table",4))

IMPORTHTML结果是

Forward Annual Dividend Rate 4    2.04
Forward Annual Dividend Yield 4   1.11%
Trailing Annual Dividend Rate 3   1.94
Trailing Annual Dividend Yield 3  1.05%
5 Year Average Dividend Yield 4   2.02
Payout Ratio 4                    32.93%
Dividend Date 3                   Mar 11, 2020
Ex-Dividend Date 4                Feb 18, 2020
Last Split Factor 2               2:1
Last Split Date 3                 Feb 17, 2003

我是TRANSPOSING准备查询数据的结果:

Forward Annual Dividend Rate 4  Forward Annual Dividend Yield 4 Trailing Annual Dividend Rate 3 ...
2.04                            1.11%                           1.94                            ...

[我需要的是Ex-Dividend Date 4列的值(因此:Feb 18, 2020)(后来还有其他列,因此我正在寻求通用解决方案)。我尝试了多种方法(请参阅下文,但所有方法均会导致#VALUE!错误:

=QUERY(TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT","table",4)), "SELECT * LIMIT 2 OFFSET 1 WHERE COL=""Ex-Dividend Date 4"")")

=QUERY(TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT","table",4)), "SELECT [Ex-Dividend Date 4] LIMIT 2 OFFSET 1")

如何正确查询该表?

web-scraping google-sheets google-sheets-formula google-sheets-query google-query-language
2个回答
0
投票

尝试:

=INDEX(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT", 
 "table", 4), 8, 2)

或已格式化:

=TEXT(INDEX(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT", 
 "table", 4), 8, 2), "mm/dd/yyyy")

QUERY中:

=QUERY(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT", 
 "table", 4), "select Col2 where Col1 contains 'Ex-Dividend Date 4'", 0)

0
投票

使用QUERY,您也可以尝试:

=QUERY(TRANSPOSE(IMPORTHTML("https://finance.yahoo.com/quote/MSFT/key-statistics?p=MSFT","table",4)), "select Col8")
© www.soinside.com 2019 - 2024. All rights reserved.