我正在尝试使用 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>
您需要指定引擎。
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)