python读取excel的第一个sheet的第三列,如果第三列的单元格为NaN,则将除表头之外第三列的单元格填上第十列除以第十一列的值,如果第十一列的值为字符串,则跳过
时间: 2023-06-04 12:02:57 浏览: 207
很高兴为您解答问题!以下是Python读取Excel的第一个sheet的第三列,进行相应处理的代码:
```python
import pandas as pd
# 读取Excel文件
df = pd.read_excel('your_excel_file.xlsx')
# 获取第一个sheet
sheet = df.parse(0)
# 获取第三列的数据
col_3 = sheet.iloc[:, 2]
# 遍历第三列的数据进行处理
for i, val in col_3.items():
if pd.isna(val):
# 如果第三列的单元格为NaN,则将除表头之外第三列的单元格填上第十列除以第十一列的值
sheet.iloc[i, 2] = sheet.iloc[i, 9] / sheet.iloc[i, 10]
elif isinstance(sheet.iloc[i, 10], str):
# 如果第十一列的值为字符串,则跳过
continue
# 输出处理后的数据
print(sheet)
```
希望可以帮到您!如果还有其他问题,请随时提出。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)