My dataframe is like this:
a = pd.DataFrame({
'Column A': [1, np.nan, 7],
'Column B': [np.nan, 2, 3],
'Column C': [np.nan, 2, np.nan]
})
I can use this index below and get the desired outcome 7.
a["Column A"][2]
However, when I want to find the last one, this one below doesn’t work. What could be the reason for that?
a["Column A"][-1]
>Solution :
Because indexing is not positional but by label. For positional indexing use iloc:
a["Column A"].iloc[-1]