我有一个关于将 xlsx 文件导入 Python 的基本问题。我已经检查了很多关于同一主题的回复,但是无论我尝试什么,我仍然无法将我的文件导入 Python。这是我的代码和我收到的错误:
import pandas as pd
import xlrd
file_location = 'C:\Users\cagdak\Desktop\python_self_learning\Coursera\sample_data.xlsx'
workbook = xlrd.open_workbook(file_location)
错误:
IOError: [Errno 2] No such file or directory: 'C:\\Users\\cagdak\\Desktop\\python_self_learning\\Coursera\\sample_data.xlsx'
原文由 Cagdas Kanar 发布,翻译遵循 CC BY-SA 4.0 许可协议
使用 pandas 可以直接获取 Excel 文件的一列。这是代码。