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
CodePudding user response:
Perhaps this works:
df['G'].notna().sum()
Example:
import pandas as pd
df = pd.read_excel('test.xlsx')
df['A'].notna().sum()
result: 3
df['A'].notna().sum()
result: 1
CodePudding user response:
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