当前位置:网站首页>About the basic operation of xlrd Library (for beginners)
About the basic operation of xlrd Library (for beginners)
2022-06-21 17:52:00 【Elite cadre flaw light】
xlrd Is one for reading excel The library of , Extremely fast reading , It is easy to use , Is read excel The first choice for Libraries .
The following goes to the text :
To read excel, First you have to get its path
import xlrd
path=r'C:\Users\gztsrayz\Desktop\ yogurt .xlsx'
wb = xlrd.open_workbook(path)In fact, this is just a choice , Not really open excel, That's why I recommend xlrd The place of , Reading some big excel When , Omitting the opening and closing steps can save us a lot of time .
The next step is to narrow down our scope step by step
name_list = wb.sheet_names() # obtain excel All table names for , Of course, you can not use this if you know
ws=wb.sheet_by_name(' Summary ')
#ws=wb.sheet_by_index(1) # Select a table according to its name or location
nrows=ws.nrows # Get the maximum number of lines
ncols=ws.ncols # Get the maximum number of columns
ps: The maximum number of rows and columns obtained here , The empty rows and columns in the middle are also counted ,
If you don't want it, you can filter out empty rows and columns when you use it
ws.row_values(5) # Get the data of the fourth row
ws.col_values(4) # Get the data of the third column
ws.cell_value(2,2) # obtain C3 Cell data
ps: Through these three lines of code , We can see that ,xlrd While reading the data , The reading positions are all yours ( Input location +1)
This is different from most other libraries !!Through the above code , We found that :xlrd The data read from rows and columns is output in the form of a list , So since it's a list , That means we can customize his order
list1=[]
for i in range(0,nrows):
# We can even be in for Add judgment under the loop to filter
list1.append([ws.cell_value(i,3),ws.cell_value(i,4),ws.cell_value(i,1),
ws.cell_value(i,2),ws.cell_value(i,0)])
print(list1)
There is probably so much useful about reading , At least it should be about the same for beginners .
边栏推荐
- 直播平台开发,直播各个分类单例设计展示
- 【ORACLE】Oracle里有“time”数据类型吗?--关于对Oracle数据类型的一点研究
- Runmaide medical passed the listing hearing: it is expected that the loss will increase, with huoyunfei brothers holding about 33%
- Xticks function in MATLAB
- The way for programmers to learn
- Runmeide Healthcare a réussi l'audience d'inscription sur la liste: les pertes devraient augmenter, Huo Yunfei Brothers détenant environ 33%
- 一招教你通过焱融 SaaS 数据服务平台+ELK 让日志帮你做决策
- 不是一流大学毕业,却通过自学软件测试,进了阿里年薪初始22K
- Technical architecture of large websites | information encryption technology and key security management
- 数字藏品系统开发,NFT艺术品交易平台搭建
猜你喜欢

PingCAP 入选 2022 Gartner 云数据库“客户之声”,获评“卓越表现者”最高分

一招教你通过焱融 SaaS 数据服务平台+ELK 让日志帮你做决策
![[Oracle] is there a](/img/21/3c481be79a4f19b06a2a93ded4159f.png)
[Oracle] is there a "time" data type in oracle-- Research on Oracle data types

众安保险联合阿里健康、慧医天下 探索互联网慢病管理新模式

Volcano engine + Yanrong yrcloudfile, driving new growth of data storage

Interceptor to realize web user login

How many items should the indoor intumescent fire retardant coating meet according to BS 476-21 fire resistance standard?

Runmeide Healthcare a réussi l'audience d'inscription sur la liste: les pertes devraient augmenter, Huo Yunfei Brothers détenant environ 33%

Iso8191 test is mentioned in as 3744.1. Are the two tests the same?

list的模拟实现
随机推荐
I am about to enter my senior year and begin my most sincere confession
Jetpack compose phase
堆栈认知——栈溢出实例(ret2text)
Nacos注册中心-----从0开始搭建和使用
FragmentStatePagerAdapter 与FragmentPagerAdapter的区别
加密大崩盘,Web3游戏到底还有没有未来?5篇论文深度探讨
Stm32f1 and stm32subeide programming example - linear Hall effect sensor driver
堆栈认知——栈溢出实例(ret2shellcode)
list的模拟实现
AttributeError: module ‘cv2‘ has no attribute ‘gapi_ wip_ gst_ GStreamerPipeline‘
经纬度转换为距离
C语言与Lua的交互(实践三)
Vit is crazy, 10+ visual transformer model details
Stack cognition - Introduction to heap
潤邁德醫療通過上市聆訊:預計虧損將增加,霍雲飛兄弟持股約33%
3DE motion contour data modification
第五章 操作位和位串
Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
大型网站技术架构 | 应用服务器安全防御
C语言与Lua的交互(实践二)