-1

In My excel other columns having values if column 'A' will have values till 8 row means it will not be the same when we refer other columns 'D' OR 'E' I want to find last row of particular column. Because I need to use the number in for loop range. Kindly help

i found many answers but all are calculating if any column contains value also it will give that number. I used below

last_empty_row=len(sheet_obj['G'])+1

but it gives same result as

row=sheet_obj.max_row

This is not a duplicate question.

I do not know how it will be below link accepted answer for my question.

How to find the last row in a column using openpyxl normal workbook?

ws.max_row len(ws['A'])

will give same answer this is not the answer i am loooking for. What i am looking for is below accepted answer is correct one find last row in particular column.

Harry
  • 11
  • 4

2 Answers2

0

Perhaps this works:

df['G'].notna().sum()

Example:

enter image description here

import pandas as pd
df = pd.read_excel('test.xlsx')
df['A'].notna().sum()

result: 3

df['B'].notna().sum()

result: 1

keramat
  • 4,328
  • 6
  • 25
  • 38
0
data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18]} #you can create a dataframe or import an excel file by using pd.read_excel('filename.xlsx')
df=pd.DataFrame(data)
df['Age'].tail(1) #to find the last value of column Age

Output: 18

Ranjan
  • 19
  • 1
  • 1
  • 8
  • Data needs to have NA/empty values in order to provide correctness. See accepted answer for better input to test upon – user3041539 Feb 23 '22 at 11:14