5 @author: Frank6 """

8 importxlrd  #xlrd is a library for reading data and formatting information from Excel files, whether they are .xls or .xlsx files.9

10 data = xlrd.open_workbook(‘通讯录.xlsx‘)#打开 Excel文件11 print(type(data))12 table =data.sheets()[0]13 print(type(table))14 nrows = table.nrows #行数

15 print("行数:{}".format(nrows))16 ncols = table.ncols #列数

17 print("列数:{}".format(ncols))18 for i inrange(0,nrows):19 rowValues = table.row_values(i) #某一行数据

20 #print(type(rowValues))

21 #print(rowValues)

22 print("姓名:{}电话:{}".format(rowValues[0], rowValues[1]))

xlrd.open_workbook(filename=None, logfile=<_io.textiowrapper name="‘<stdout">‘ mode=‘w‘ encoding=‘UTF-8‘>, verbosity=0, use_mmap=1, file_contents=None, encoding_override=None, formatting_info=False, on_demand=False, ragged_rows=False)

打开一个Excel文件。

这里先简单的介绍基本的参数,以后有用到再添加。

Parameters:

filename – The path to the spreadsheet file to be opened.

指定要打开文件的路径

logfile – An open file to which messages and diagnostics are written

Returns:

An instance of the Book class.

book.sheets()

Return:  A list of all sheets in the book. 返回Excel中所有的表,并保存在list中。

All sheets not already loaded will be loaded.

classxlrd.sheet.Sheet(book, position, name, number)

Contains the data for one worksheet.

In the cell access functions, rowx is a row index, counting from zero, and colx is a column index, counting from zero. Negative values for row/column indexes and slice positions are supported in the expected fashion.

Note: You don’t instantiate this class yourself. You access Sheet objects via the Book object that was returned when you called xlrd.open_workbook().

nrows= 0

Number of rows in sheet. A row index is in range(thesheet.nrows).

ncols= 0

Nominal number of columns in sheet. It is one more than the maximum column index found, ignoring trailing empty cells. See also the ragged_rows parameter to open_workbook() and row_len().

row_values(rowx, start_colx=0, end_colx=None)

Returns a slice of the values of the cells in the given row.该函数返回一个list,默认包含这一行的cells的所有内容。

原文:https://www.cnblogs.com/black-mamba/p/9092563.html

1 #-*- coding: utf-8 -*-2 """3 Created on Thu May 24 13:53:10 201845 @author: Frank6 """78 importxlrd  #xlrd is a library for reading data and formatting information from Excel files, whether they are... 一文搞定Pandas中的数据合并 pandas实现两个dataframe数据的合并:按行和按列 在实际处理数据业务需求中,我们经常会遇到这样的需求:将多个表连接起来再进行数据的处理和分析,类似SQL中的连接查询功能。 pandas中也提供了几种方法来实现这个功能,表现最突出、使用最为广泛的方法是merge。 注意:记得重新复制,否则数据无法保存下来,即: data = data.append(xx)
目前来说, Access 数据库的使用度相对较少,所以在使用 Python 操作 Access 数据库 文件 时,相应的文章和教程也较少。为了解决各位在类似场景下的难题,特意写文章如下: 1.安装模块pyodbc pip install pyodbc 打开命令指示行,然后正常安装ODBC模块即可 2.安装驱动程序 这个主要跟电脑上的office版本有关,如果是64位的,请安装64位,如果是2016版的...
我有一个 Excel 表格, 想整体作为一张表写入数据库,方便以后处理。 想法是这样:先用pandas 读取 Excel 表格,将表格内容转化成一个dataframe数据,然后将这个df数据整体写入数据库。 刚开始的时候,没弄清楚,到底要不要先在数据库中建好表, 还有相应字段… 1. 读取 Excel 表格数据 需要的模块 pandas sqlalchemy pymysql 我的 Excel 文件 my....
你可以使用 Python 的 `pandas` 库来 读取 Excel 文件 。 `pandas` 提供了一个简单的函数 `pandas.read_ excel ()`,可以轻松地将 Excel 文件 读入为 `pandas` 数据帧。 你可以通过以下方式安装 `pandas`: pip install pandas 然后你就可以使用下面的代码来 读取 Excel 文件 了: ``` python import pandas as pd # 读取 Excel 文件 df = pd.read_ excel ('file.xlsx') # 打印前几行数据 print(df.head()) 你也可以指定 读取 特定的工作表,例如: ``` python import pandas as pd # 读取 特定的工作表 df = pd.read_ excel ('file.xlsx', sheet_name='Sheet1') # 打印前几行数据 print(df.head()) 你也可以使用 `skiprows` 参数跳过 文件 的前几行,例如: ``` python import pandas as pd # 跳过 文件 的前两行 df = pd.read_ excel ('file.xlsx', skiprows=2) # 打印前几行数据 print(df.head()) 这些只是 `pandas.read_ excel ()` 函数的一些基本用法。你可以在[官方文档](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_ excel .html)中了解更多关于此函数的用法。