gpt4 book ai didi

Python 使用 pandas 读取 Excel 中的问题

转载 作者:行者123 更新时间:2023-12-01 01:56:08 26 4
gpt4 key购买 nike

您好,我是开源技术的新手 - 我正在使用 Anaconda3-5.1.0-Windows-x86_64 和 Microsoft Excel 2016。使用 pandas 的 Excel 读取操作会抛出错误,因为以下代码未找到文件错误。

import pandas as pd 
from pandas import ExcelWriter
from pandas import ExcelFile
path= "D:\sample.xlsx"
print(path)
df = pd.read_excel(path, sheet_name = 'Sheet1')
print('Column headings:')
print(df.columns)

错误消息为 FileNotFoundError: [Errno 2] No such file or directory: 'D:\sample.xlsx'-

我试图读取“D:\sample.xlsx”,但该函数尝试将文件打开为“D:\sample.xlsx”。

任何人都可以就这个问题提供建议,或者让我知道所需的更多详细信息。

最佳答案

改变

path= "D:\sample.xlsx"

path= r"D:\sample.xlsx" or path= "D:\\sample.xlsx"

关于Python 使用 pandas 读取 Excel 中的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50169144/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com