Cách đọc file Excel trong Python bằng Pandas read_excel()
3 phút đọc27/08/2025
Về tác giả
I have over 5 years of experience writing technical documentation for tech products, making them accessible and user-friendly. My focus is always on providing clear and precise information.
@#@
Tôi đã có hơn 5 năm kinh nghiệm viết tài liệu kỹ thuật cho các sản phẩm công nghệ, giúp người dùng dễ dàng tiếp cận và sử dụng. Tôi luôn tập trung vào việc cung cấp thông tin chính xác và dễ hiểu.
Cập nhật thông tin mới nhấtNhận các thông tin mới nhất về mối đe dọa, báo cáo an ninh mạng từ CyStack về hòm thư điện tử của bạn
{"success":true,"head":"<title>Cách đọc file Excel trong Python bằng Pandas read_excel() - CyStack Tutorial</title>\n<meta name=\"description\" content=\"Tìm hiểu cách đọc file Excel trong Python với thư viện Pandas và OpenPyXL. Hướng dẫn chi tiết kèm ví dụ code giúp bạn xử lý dữ liệu nhanh chóng và hiệu quả.\"/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-video-preview:-1, max-image-preview:large\"/>\n<link rel=\"canonical\" href=\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/\" />\n<meta property=\"og:locale\" content=\"en_US\" />\n<meta property=\"og:type\" content=\"article\" />\n<meta property=\"og:title\" content=\"Cách đọc file Excel trong Python bằng Pandas read_excel() - CyStack Tutorial\" />\n<meta property=\"og:description\" content=\"Tìm hiểu cách đọc file Excel trong Python với thư viện Pandas và OpenPyXL. Hướng dẫn chi tiết kèm ví dụ code giúp bạn xử lý dữ liệu nhanh chóng và hiệu quả.\" />\n<meta property=\"og:url\" content=\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/\" />\n<meta property=\"og:site_name\" content=\"CyStack Tutorial\" />\n<meta property=\"article:tag\" content=\"vi\" />\n<meta property=\"article:section\" content=\"Python\" />\n<meta property=\"og:updated_time\" content=\"2026-08-03T18:18:46+07:00\" />\n<meta property=\"og:image\" content=\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\" />\n<meta property=\"og:image:secure_url\" content=\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\" />\n<meta property=\"og:image:width\" content=\"1200\" />\n<meta property=\"og:image:height\" content=\"630\" />\n<meta property=\"og:image:alt\" content=\"Cách đọc file Excel trong Python\" />\n<meta property=\"og:image:type\" content=\"image/jpeg\" />\n<meta property=\"article:published_time\" content=\"2025-08-27T10:03:57+07:00\" />\n<meta property=\"article:modified_time\" content=\"2026-08-03T18:18:46+07:00\" />\n<meta name=\"twitter:card\" content=\"summary_large_image\" />\n<meta name=\"twitter:title\" content=\"Cách đọc file Excel trong Python bằng Pandas read_excel() - CyStack Tutorial\" />\n<meta name=\"twitter:description\" content=\"Tìm hiểu cách đọc file Excel trong Python với thư viện Pandas và OpenPyXL. Hướng dẫn chi tiết kèm ví dụ code giúp bạn xử lý dữ liệu nhanh chóng và hiệu quả.\" />\n<meta name=\"twitter:image\" content=\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\" />\n<meta name=\"twitter:label1\" content=\"Written by\" />\n<meta name=\"twitter:data1\" content=\"Chris Pham\" />\n<meta name=\"twitter:label2\" content=\"Time to read\" />\n<meta name=\"twitter:data2\" content=\"3 minutes\" />\n<script type=\"application/ld+json\" class=\"rank-math-schema\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https://blog.cystack.org/tutorial/#person\",\"name\":\"CyStack Tutorial\"},{\"@type\":\"WebSite\",\"@id\":\"https://blog.cystack.org/tutorial/#website\",\"url\":\"https://blog.cystack.org/tutorial\",\"name\":\"CyStack Tutorial\",\"publisher\":{\"@id\":\"https://blog.cystack.org/tutorial/#person\"},\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"@id\":\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\",\"url\":\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\",\"width\":\"1200\",\"height\":\"630\",\"caption\":\"C\\u00e1ch \\u0111\\u1ecdc file Excel trong Python\",\"inLanguage\":\"en-US\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":\"1\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":\"2\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/category/python/\",\"name\":\"Python\"}},{\"@type\":\"ListItem\",\"position\":\"3\",\"item\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/\",\"name\":\"C\\u00e1ch \\u0111\\u1ecdc file Excel trong Python b\\u1eb1ng Pandas read_excel()\"}}]},{\"@type\":\"WebPage\",\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/#webpage\",\"url\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/\",\"name\":\"C\\u00e1ch \\u0111\\u1ecdc file Excel trong Python b\\u1eb1ng Pandas read_excel() - CyStack Tutorial\",\"datePublished\":\"2025-08-27T10:03:57+07:00\",\"dateModified\":\"2026-08-03T18:18:46+07:00\",\"isPartOf\":{\"@id\":\"https://blog.cystack.org/tutorial/#website\"},\"primaryImageOfPage\":{\"@id\":\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\"},\"inLanguage\":\"en-US\",\"breadcrumb\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/#breadcrumb\"}},{\"@type\":\"Person\",\"@id\":\"https://blog.cystack.org/tutorial/author/codeweaver/\",\"name\":\"Chris Pham\",\"url\":\"https://blog.cystack.org/tutorial/author/codeweaver/\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https://secure.gravatar.com/avatar/7a3584c941fa360ac061b2a8f15684ced7b92daa1f09481be135a684d989e9b9?s=96&d=mm&r=g\",\"url\":\"https://secure.gravatar.com/avatar/7a3584c941fa360ac061b2a8f15684ced7b92daa1f09481be135a684d989e9b9?s=96&d=mm&r=g\",\"caption\":\"Chris Pham\",\"inLanguage\":\"en-US\"}},{\"@type\":\"BlogPosting\",\"headline\":\"C\\u00e1ch \\u0111\\u1ecdc file Excel trong Python b\\u1eb1ng Pandas read_excel() - CyStack Tutorial\",\"keywords\":\"\\u0111\\u1ecdc file Excel trong Python,Pandas\",\"datePublished\":\"2025-08-27T10:03:57+07:00\",\"dateModified\":\"2026-08-03T18:18:46+07:00\",\"articleSection\":\"Python\",\"author\":{\"@id\":\"https://blog.cystack.org/tutorial/author/codeweaver/\",\"name\":\"Chris Pham\"},\"publisher\":{\"@id\":\"https://blog.cystack.org/tutorial/#person\"},\"description\":\"T\\u00ecm hi\\u1ec3u c\\u00e1ch \\u0111\\u1ecdc file Excel trong Python v\\u1edbi th\\u01b0 vi\\u1ec7n Pandas v\\u00e0 OpenPyXL. H\\u01b0\\u1edbng d\\u1eabn chi ti\\u1ebft k\\u00e8m v\\u00ed d\\u1ee5 code gi\\u00fap b\\u1ea1n x\\u1eed l\\u00fd d\\u1eef li\\u1ec7u nhanh ch\\u00f3ng v\\u00e0 hi\\u1ec7u qu\\u1ea3.\",\"name\":\"C\\u00e1ch \\u0111\\u1ecdc file Excel trong Python b\\u1eb1ng Pandas read_excel() - CyStack Tutorial\",\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/#richSnippet\",\"isPartOf\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/#webpage\"},\"image\":{\"@id\":\"https://s2.cystack.net/tutorial/27100154/cach-doc-file-excel-trong-python.jpg\"},\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https://blog.cystack.org/tutorial/vi/2025/08/27/cach-doc-file-excel-trong-python/#webpage\"}}]}</script>\n"}
Trong bài viết này, chúng ta sẽ học cách đọc file Excel trong Python bằng Pandas read_excel().

Chúng ta có thể sử dụng hàm read_excel() của mô-đun pandas để đọc dữ liệu từ tệp Excel và lưu vào một đối tượng DataFrame. Trong Excel, dữ liệu được tổ chức dưới dạng bảng hai chiều, và DataFrame cũng mô phỏng chính xác cấu trúc bảng hai chiều này.
Ví dụ về pandas read_excel()
Giả sử chúng ta có một tệp Excel với hai sheet: Employees và Cars. Hàng đầu tiên chứa tiêu đề của bảng.

Dữ liệu các sheet trong tệp Excel
Ví dụ sau minh họa cách đọc dữ liệu từ sheet “Employees” và in nội dung của nó ra màn hình.
import pandas
excel_data_df = pandas.read_excel('records.xlsx', sheet_name='Employees')
print whole sheet data
print(excel_data_df)
Kết quả:
EmpID EmpName EmpRole
0 1 Pankaj CEO
1 2 David Lee Editor
2 3 Lisa Ray Author
Tham số đầu tiên là tên tệp Excel.
Tham số sheet_name xác định tên sheet cần đọc từ tệp Excel.
Khi in đối tượng DataFrame, kết quả là một bảng hai chiều, trông tương tự như nội dung trong bảng tính Excel.
Danh sách tiêu đề cột trong bảng tính Excel
Chúng ta có thể lấy danh sách các tiêu đề cột bằng thuộc tính columns của đối tượng DataFrame.
print(excel_data_df.columns.ravel())
Kết quả:
['EmpID' 'EmpName' 'EmpRole']
In dữ liệu của một cột
Chúng ta có thể truy xuất dữ liệu của một cột và chuyển đổi nó thành danh sách các giá trị như sau:
print(excel_data_df['EmpName'].tolist())
Kết quả:
['Pankaj', 'David Lee', 'Lisa Ray']
Sử dụng usecols với read_excel()
Chúng ta có thể chỉ định các tên cột cần đọc từ tệp Excel. Đây là giải pháp hiệu quả khi bạn chỉ quan tâm đến một số cột cụ thể trong bảng tính.
import pandas
excel_data_df = pandas.read_excel('records.xlsx', sheet_name='Cars', usecols=['Car Name', 'Car Price'])
print(excel_data_df)
Kết quả:
Car Name Car Price
0 Honda City 20,000 USD
1 Bugatti Chiron 3 Million USD
2 Ferrari 458 2,30,000 USD
Đọc tệp Excel không có hàng tiêu đề
Nếu bảng tính Excel không có hàng tiêu đề, bạn có thể đặt tham số header thành None:
excel_data_df = pandas.read_excel('records.xlsx', sheet_name='Numbers', header=None)
Ngược lại, nếu truyền một giá trị nguyên cho header (ví dụ 3), thì hàng thứ 3 sẽ được xử lý làm hàng tiêu đề, và dữ liệu sẽ được đọc bắt đầu từ hàng ngay sau đó. Tất cả dữ liệu nằm trước hàng tiêu đề sẽ bị bỏ qua.
Chuyển đổi Sheet Excel sang Dict, CSV và JSON
Đối tượng DataFrame cung cấp nhiều phương thức tiện ích để chuyển đổi dữ liệu dạng bảng sang các định dạng Dict, CSV hoặc JSON.
excel_data_df = pandas.read_excel('records.xlsx', sheet_name='Cars', usecols=['Car Name', 'Car Price'])
print('Excel Sheet to Dict:', excel_data_df.to_dict(orient='record'))
print('Excel Sheet to JSON:', excel_data_df.to_json(orient='records'))
print('Excel Sheet to CSV:\n', excel_data_df.to_csv(index=False))
Kết quả:
Excel Sheet to Dict: [{'Car Name': 'Honda City', 'Car Price': '20,000 USD'}, {'Car Name': 'Bugatti Chiron', 'Car Price': '3 Million USD'}, {'Car Name': 'Ferrari 458', 'Car Price': '2,30,000 USD'}]
Excel Sheet to JSON: [{"Car Name":"Honda City","Car Price":"20,000 USD"},{"Car Name":"Bugatti Chiron","Car Price":"3 Million USD"},{"Car Name":"Ferrari 458","Car Price":"2,30,000 USD"}]
Excel Sheet to CSV:
Car Name,Car Price
Honda City,"20,000 USD"
Bugatti Chiron,3 Million USD
Ferrari 458,"2,30,000 USD"
Tài liệu tham khảo
Tài liệu API read_excel() của pandas.