用python读取excel数据
时间: 2024-05-12 21:16:38 浏览: 58
Msptest-python读取excel数据
好的,关于读取Excel数据,我可以提供以下几种方式:
1.使用pandas库读取Excel文件
```
import pandas as pd
df = pd.read_excel("your_file.xlsx")
print(df)
```
2.使用xlwt和xlrd库读取和写入Excel文件
```
import xlwt
import xlrd
#读取excel
workbook = xlrd.open_workbook('your_file.xlsx')
worksheet = workbook.sheet_by_index(0)
num_rows = worksheet.nrows
num_cols = worksheet.ncols
for curr_row in range(num_rows):
row_data = []
for curr_col in range(num_cols):
data = worksheet.cell_value(curr_row, curr_col)
row_data.append(data)
print(row_data)
#写入excel
workbook = xlwt.Workbook(encoding='utf-8')
worksheet = workbook.add_sheet("sheet1")
worksheet.write(0, 0, "hello")
worksheet.write(0, 1, "world")
workbook.save('new_file.xls')
```
以上两种方法都能读取和写入Excel文件,具体使用取决于你的需求和习惯。
阅读全文