I have a dataframe with these indices and values:
gf = df.drop(df.index[])
You are probably causing pandas to switch between
.iloc (index based) and
.loc (label based) indexing.
All arrays in Python are 0 indexed. And I notice that indexes in your DataFrame are starting from 1. So when you run
df[df.column] pandas realizes that there is no index named 0, and falls back to
.iloc which locates things by array indexing. Therefore it returns what it finds at the first location of the array, which is
When you run
df[df.column] however, pandas realizes that there is a index label 1, and uses
.loc which returns what it finds at that label, which again happens to be
When you delete the first row, your DataFrame does not have index labels 0 and 1. So when you go to locate elements at those places in the way you are, it does not return
None to you, but instead falls back on array based indexing and returns elements from the 0th and 1st places in the array.
To enforce pandas to use one of the two indexing techniques, use
.loc is label based, and will raise
KeyError if you try
.iloc is index based and will return
'example' when you try
These commands are bad practice:
df.loc[row_label, col_label]; or
df.iloc[row_index, col_index]; or
See Different Choices for Indexing for more information.