I have a data table I am pulling from excel that looks like this:
Raw pH TAPA
8.20 30
8.21 29
8.22 28.5
8.23 28
8.24 27
8.25 26.5
8.26 26
I usually have no problem looking up a number in one column based on another column. For instance, when, I code:
df = pd.read_excel('Conversions.xlsx', 'Sheet1')
df2=df.loc[df['Raw pH'] == 8.21, 'TAPA']
print(df2)
I would expect it to return "29". However, it is only working when I look for the first pH value of 8.20;
df2=df.loc[df['Raw pH'] == 8.20, 'TAPA']
print(df2)
Returns:
0 30.0
Name: TAPA, dtype: float64
When I try any other number, such as:
df2=df.loc[df['Raw pH'] == 8.23, 'TAPA']
print(df2)
I simply get an empty value:
Series([], Name: TAPA, dtype: float64)
If I try it with iloc:
df2=df.loc[df['Raw pH'] == 8.23, 'TAPA'].iloc[0]
print(df2)
I get the error IndexError: single positional indexer is out-of-bounds.
If I try the iloc()
method with 8.2, it returns 30.0 as expected.
Why am I getting back empty values for everything below the first data row?