The following code works perfectly with row 0, exact march with 'A', but throws an error for other rows, here exact match with 'B'. Any idea why?
df = pd.DataFrame({'Column1': ['A', 'B', 'C'], 'Column2': [0, 1, 2]})
print(df.loc[df["Column1"] == 'A'].Column2[0])
df = pd.DataFrame({'Column1': ['A', 'B', 'C'], 'Column2': [0, 1, 2]})
print(df.loc[df["Column1"] == 'B'].Column2[0])
Here is the error message:
Traceback (most recent call last):
File "<ipython-input-105-749b69acaacd>", line 2, in <module>
print(df.loc[df["Column1"] == 'B'].Column2[0])
File "/anaconda3/lib/python3.7/site-packages/pandas/core/series.py", line 868, in __getitem__
result = self.index.get_value(self, key)
File "/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py", line 4375, in get_value
tz=getattr(series.dtype, 'tz', None))
File "pandas/_libs/index.pyx", line 81, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 89, in pandas._libs.index.IndexEngine.get_value
File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 987, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 993, in pandas._libs.hashtable.Int64HashTable.get_item