python求excel的最大行_OpenPyXL:需要在Excel中具有数据的列中的最大行数

本文介绍了如何在Python中使用OpenPyXL库来找到Excel文件中特定列含有数据的最后一行。在场景中,作者需要从数据库获取数据并将其追加到Excel工作表的某一列末尾。提供了三种解决方案,包括利用pandas读取数据并计算最大行数,以及直接遍历特定列的单元格检查非空值。
摘要由CSDN通过智能技术生成

I need the last row in a particular column that contains data in Excel. In openpyxl sheet.max_row or max_column gets us the maximum row or column in the whole sheet. But what I want is for a particular column.

My scenario is where I have to get some values from database and append it to the end of a particular column in Excel sheet.

In this screenshot, if I want max_column containing data in column 'C', it should return 10:

In the above image if I want last cell containing data of column 'C', it should return 10

------------- Solution 1 --------------------

import pandas as pd

# lt is the dataframe containing the data to be loaded to excel file

for index,i in enumerate(lt):

panda_xl_rd = pd.read_excel('file.xlsx',"sheet_Name") # Panda Dataframe

m

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值