Rishikesh Agrawani
2018-11-30 06:24:51 UTC
`df.irow()` is deprecated in new version of pandas.
Visit and check
http://pandas.pydata.org/pandas-docs/version/0.19/generated/pandas.Series.irow.html
... "name": ["A", "D", "A", "E", "A", "D", "E", "D", "H", "E"],
... "day": [4, 3, 2, 1, 6, 10, 9, 8, 7, 5],
... "score": [2, 1, 6, 4, 3, 7, 3, 2, 8, 4]
... })
name day score
0 A 4 2
1 D 3 1
2 A 2 6
3 E 1 4
4 A 6 3
5 D 10 7
6 E 9 3
7 D 8 2
8 H 7 8
9 E 5 4
'E'
'E'
Visit and check
http://pandas.pydata.org/pandas-docs/version/0.19/generated/pandas.Series.irow.html
import pandas as pd
df = pd.DataFrame({
df = pd.DataFrame({
... "day": [4, 3, 2, 1, 6, 10, 9, 8, 7, 5],
... "score": [2, 1, 6, 4, 3, 7, 3, 2, 8, 4]
... })
df
0 A 4 2
1 D 3 1
2 A 2 6
3 E 1 4
4 A 6 3
5 D 10 7
6 E 9 3
7 D 8 2
8 H 7 8
9 E 5 4
df["name"].iloc[-1]
df["name"].iat[-1]
Hello,
trying to get the last row of a data frame with python index style ([-1]),
I found the following strange behaviour of pandas.
# this works as expected
df1 = DataFrame({'A':[0,1,2,3]},index=date_range('1/1/2000',periods=4))
df1['A'][-1]
3
# this gives errors
df2 = DataFrame({'A':[0,1,2,3]})
df2['A'][-1]
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-x86_64.egg/pandas/core/series.py",
line 431, in __getitem__
return self.index.get_value(self, key)
File
"/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-x86_64.egg/pandas/core/index.py",
line 655, in get_value
return self._engine.get_value(series, key)
File "engines.pyx", line 79, in pandas.lib.IndexEngine.get_value
(pandas/src/tseries.c:107687)
File "engines.pyx", line 87, in pandas.lib.IndexEngine.get_value
(pandas/src/tseries.c:107515)
File "engines.pyx", line 129, in pandas.lib.IndexEngine.get_loc
(pandas/src/tseries.c:108224)
File "hashtable.pyx", line 350, in pandas.lib.Int64HashTable.get_item
(pandas/src/tseries.c:15610)
File "hashtable.pyx", line 356, in pandas.lib.Int64HashTable.get_item
(pandas/src/tseries.c:15564)
KeyError: -1
trying to get the last row of a data frame with python index style ([-1]),
I found the following strange behaviour of pandas.
# this works as expected
df1 = DataFrame({'A':[0,1,2,3]},index=date_range('1/1/2000',periods=4))
df1['A'][-1]
3
# this gives errors
df2 = DataFrame({'A':[0,1,2,3]})
df2['A'][-1]
File "<stdin>", line 1, in <module>
File
"/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-x86_64.egg/pandas/core/series.py",
line 431, in __getitem__
return self.index.get_value(self, key)
File
"/usr/local/lib/python2.7/dist-packages/pandas-0.8.1-py2.7-linux-x86_64.egg/pandas/core/index.py",
line 655, in get_value
return self._engine.get_value(series, key)
File "engines.pyx", line 79, in pandas.lib.IndexEngine.get_value
(pandas/src/tseries.c:107687)
File "engines.pyx", line 87, in pandas.lib.IndexEngine.get_value
(pandas/src/tseries.c:107515)
File "engines.pyx", line 129, in pandas.lib.IndexEngine.get_loc
(pandas/src/tseries.c:108224)
File "hashtable.pyx", line 350, in pandas.lib.Int64HashTable.get_item
(pandas/src/tseries.c:15610)
File "hashtable.pyx", line 356, in pandas.lib.Int64HashTable.get_item
(pandas/src/tseries.c:15564)
KeyError: -1