How to Take index of Last Cell in ColumnB?
I will iterate through all rows, by taking values in there. For that iteration i wanted to take index value of max row in particular column with pandas in python. df['columnNameB'].idxmax()
I also tried using axis=1
or axis='columns
gave other strange errors.
idxmax()
works in Series of pandas and df['colNameB']
already gives as a series of columnB values, then why idxmax()
does not work properly?
code is below;
#reading from csv file url-s
def readCSV(path_csv):
df=pd.read_csv(path_csv)
return df
fileCSV=readCSV(r'C:\Users\Admin\Downloads\urls.csv')
print(fileCSV['columnURLnames'].idxmax())
"""for i in range(len(fileCSV.columns(1))):
xUrl=fileCSV.iloc[0,i]
print(xUrl)
"""
edit:
columnA columnB columnC
0 book www.amazon.com=page?1.. onstock
1 headphone www.amazon.com=page?1.. outstock
2 NaN www.alibaba.com.. NaN
3 NaN www.amazon.... NaN
4 lightbulb NaN inStock
I need to get number 3. Because index of max value in columnB is 3
solved: from SO
length_of_column_urls=fileCSV['columnURLnames'].last_valid_index()
for i in range(0, length_of_column_urls+1 ):
xUrl=fileCSV.iloc[i,1]
print(xUrl)