如何从Google Drive获取Excel文件数据

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

我正在尝试使用 Python 读取存储在 Google Drive 中的 Student.xlsx 文件,代码如下;但是,我遇到了错误。请检查代码和错误消息,并提供正确的代码。

import pandas as pd
url = "https://docs.google.com/spreadsheets/d/1-6-dNTXR3YLAvRIDRWf9DQsdXw3EAJWt/edit?usp=sharing&ouid=105182257404870437876&rtpof=true&sd=true"
url_for_pandas = url.replace("/edit?usp=share_link", "/export?format=xlsx")
df = pd.read_excel(url_for_pandas)
print(df)

see error 

  File "c:\mainfol\mfatt\tempCodeRunnerFile.py", line 4, in <module>
    df = pd.read_excel(url_for_pandas)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ali\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\excel\_base.py", line 495, in read_excel    io = ExcelFile(
         ^^^^^^^^^^
  File "C:\Users\Ali\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\excel\_base.py", line 1554, in __init__ 
    raise ValueError(
ValueError: Excel file format cannot be determined, you must specify an engine manually.
PS C:\mainfol\mfatt> 

关注

raise ValueError(
ValueError: Excel file format cannot be determined, you must specify an engine manually.
PS C:\mainfol\mfatt> 
python
1个回答
0
投票

您需要指定引擎。

import pandas as pd
url = "https://docs.google.com/spreadsheets/d/1-6-dNTXR3YLAvRIDRWf9DQsdXw3EAJWt/edit?usp=sharing&ouid=105182257404870437876&rtpof=true&sd=true"
url_for_pandas = url.replace("/edit?usp=share_link", "/export?format=xlsx")

df = pd.read_excel(url_for_pandas, engine='openpyxl')
print(df)
© www.soinside.com 2019 - 2024. All rights reserved.