Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas iloc vs direct slicing?

Tags:

python

pandas

I've read a lot of discussion about iloc vs loc and I understand the difference but what I don't understand is what's the difference between:

indexed_data['var'][0:10]

vs

indexed_data['var'].iloc[0:10]

These seem to be the same thing and give the same output.

Am I missing something? Thanks!

like image 303
Rob Avatar asked Aug 31 '17 14:08

Rob


1 Answers

As a complement to the other answers, also observe the following note from the docs:

While standard Python / Numpy expressions for selecting and setting are intuitive and come in handy for interactive work, for production code, we recommend the optimized pandas data access methods, .at, .iat, .loc and .iloc.

like image 81
Oliver Sieweke Avatar answered Oct 02 '22 20:10

Oliver Sieweke