读xlsx文件wb1的一个名为第广东各学科的sheet 对于sheet的每一行,读取第B行的数据,记为tmp1,读取第C行文件,记为tmp2, 算出TMP = tmp1/tmp2*10并按照第E和第F行的内容分类,输出结果
时间: 2023-05-24 08:06:42 浏览: 42
以下是Python代码实现:
```python
import openpyxl
# 打开Excel文件
wb1 = openpyxl.load_workbook('文件路径.xlsx')
# 选择指定的sheet
sheet = wb1['第广东各学科']
# 存储结果的字典,key为分类,value为结果列表
result = {}
# 遍历每一行
for row in sheet.iter_rows(min_row=2):
# 读取第B和第C列的数据,计算出TMP
tmp1 = row[1].value
tmp2 = row[2].value
if tmp1 is None or tmp2 is None:
continue
tmp = tmp1 / tmp2 * 10
# 按照第E和第F列的内容分类
category = row[4].value + '-' + row[5].value
if category not in result:
result[category] = []
result[category].append(tmp)
# 输出结果
for category, values in result.items():
print(category, sum(values) / len(values))
```
其中`文件路径.xlsx`需要替换为实际的Excel文件路径。
相关问题
//读xlsx文件wb1的一个名为第广东各学科的sheet //对于sheet的每一行,读取第B行的数据,记为tmp1,读取第C行文件,记为tmp2, 算出TMP = tmp1/tmp2*10并按照第E和第F行的内容分类 //在一个新表中,对于每一个学校,列出所有含有的学科(按TMP=0~1‰, TMP = 1‰~5‰, TMP = 5‰~1%分类,输出格式如下: //序号 机构名称 进入ESI前1‰学科 进入ESI前1‰~5%学科 进入ESI前5‰~1%学科
Null is a term used in computer programming to represent a value that is uninitialized or absent. It is often used as a placeholder or placeholder value in data structures and algorithms, indicating the absence of a value or data. In many programming languages, null is distinct from other values such as zero, empty strings, and false boolean values. Null can also refer to a null character, which is used in text strings to indicate the end of a string.
用xlwings读取文件的sheet1的所有数据,并在最后一行前10列填上‘正在写入’
好的,我可以帮你实现这个功能。首先,你需要安装 `xlwings` 库,你可以使用以下命令在命令行中安装:
```
pip install xlwings
```
然后,你可以使用以下代码来读取文件的sheet1的所有数据,并在最后一行前10列填上‘正在写入’:
```python
import xlwings as xw
# 打开工作簿
wb = xw.Book('你的文件路径.xlsx')
# 选择sheet1
sheet = wb.sheets['Sheet1']
# 获取所有数据
data = sheet.used_range.value
# 在最后一行前10列填上'正在写入'
last_row = sheet.range('A1').end('down').row + 1
for col in range(10):
sheet.range((last_row, col+1)).value = '正在写入'
# 关闭工作簿
wb.close()
```
需要注意的是,你需要将 `'你的文件路径.xlsx'` 替换成你实际的文件路径。另外,如果你的文件不是 `.xlsx` 格式,需要将文件后缀名修改为实际的格式。