使用xlrd模块,可以从电子表格中检索信息。例如,可以用Python来读取、写入或修改数据。此外,用户可能必须遍历各种表,并根据一些标准检索数据,或者修改一些行和列,并执行大量工作。
xlrd模块用于从电子表格中提取数据。
安装xlrd模块命令:
pip install xlrd
输入文件 :
代码#1:
# 使用Python读取excel文件 import xlrd # 给出文件的位置 loc = ("path of file") # 打开Workbook wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # 对于第0行和第0列 sheet.cell_value(0, 0)
输出:
'NAME'
代码#2:提取行数
# 使用Python提取行数 import xlrd #给出文件的位置 loc = ("path of file") wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) sheet.cell_value(0, 0) #提取行数 print(sheet.nrows)
输出:
4
代码#3:提取列数
# 用Python程序提取列数 import xlrd loc = ("path of file") wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) # 对于第0行和第0列 sheet.cell_value(0, 0) # 提取列数 print(sheet.ncols)
输出:
3
代码#4:提取所有列名称
# 提取所有列名 import xlrd loc = ("path of file") wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) sheet.cell_value(0, 0) for i in range(sheet.ncols): print(sheet.cell_value(0, i))
输出:
NAME SEMESTER ROLL NO
代码#5:提取第一列
# 提取第一列 import xlrd loc = ("path of file") wb = xlrd.open_workbook(loc) sheet = wb.sheet_by_index(0) sheet.cell_value(0, 0) for i in range(sheet.nrows): print(sheet.cell_value(i, 0))
输出:
NAME ALEX CLAY JUSTIN
代码#6:提取特定的行值
输出:
['ALEX', 4.0, 2011272.0]]
相关推荐:《Python教程》
本篇文章就是关于Python读取excel文件的方法介绍,希望对需要的朋友有所帮助!
Atas ialah kandungan terperinci 如何使用Python读取excel文件?(代码示例). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Pythonlistscanstoreanydatatype, arraymoduleArraysstoreonetype, andnumpyarraysarefornumumericalcomputations.1) listsareversatileButlessMememory-efficient.2) arraymoduleArduleArrayRaysarememory-efficientforhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogenhomogen

KetikayyoUttemptToStoreAveFheWrongatatypeinapythonArray, anda akan menjadicounteratypeerror

Pythonlistsarepartofthestandardlibrary, sementara

Thescriptisrunningwiththewrongpythonversionduetoincorrectdefault interpretsettings

PythonArraysSupportVariousoperations: 1) SlicingExtractsSubsets, 2) Menambah/ExtendingAddSelements, 3) InsertingPlaceSelementSatSatSatSpecifics, 4) RemovingDeleteselements, 5) Sorting/ReversingChangesOrder,

NumpyarraysareessentialforapplicationRequiringeficientnumericalcomputationsanddatamanipulation.theyarecrucialindaSascience, machinelearning, fizik, kejuruteraan, danfinanceduetotheirabilitytOHandlelarge-Scaledataefisien.Forexample, infinancialanal

UseanArray.arrayoveralistinpythonwhendealingwithhomogeneousdata, criticalcode prestasi, orinterfacingwithccode.1) homogeneousdata: arrayssavemememorywithtypedelements.2)

Tidak, notalllistoperationsaresuportedByArrays, andviceversa.1) arraysdonotsupportdynamicoperationslikeappendorinsertwithoutresizing, whyimpactsperformance.2) listsdonotguaranteeconstantTimeComplexityFordirectacesscesscesscesscesscesscesscesscesscesessd.


Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

Video Face Swap
Tukar muka dalam mana-mana video dengan mudah menggunakan alat tukar muka AI percuma kami!

Artikel Panas

Alat panas

Dreamweaver CS6
Alat pembangunan web visual

SublimeText3 versi Inggeris
Disyorkan: Versi Win, menyokong gesaan kod!

mPDF
mPDF ialah perpustakaan PHP yang boleh menjana fail PDF daripada HTML yang dikodkan UTF-8. Pengarang asal, Ian Back, menulis mPDF untuk mengeluarkan fail PDF "dengan cepat" dari tapak webnya dan mengendalikan bahasa yang berbeza. Ia lebih perlahan dan menghasilkan fail yang lebih besar apabila menggunakan fon Unicode daripada skrip asal seperti HTML2FPDF, tetapi menyokong gaya CSS dsb. dan mempunyai banyak peningkatan. Menyokong hampir semua bahasa, termasuk RTL (Arab dan Ibrani) dan CJK (Cina, Jepun dan Korea). Menyokong elemen peringkat blok bersarang (seperti P, DIV),

EditPlus versi Cina retak
Saiz kecil, penyerlahan sintaks, tidak menyokong fungsi gesaan kod

Penyesuai Pelayan SAP NetWeaver untuk Eclipse
Integrasikan Eclipse dengan pelayan aplikasi SAP NetWeaver.
