Difference between pandas .iloc and .iat?

前端 未结 2 1144
眼角桃花
眼角桃花 2021-02-14 06:07

I\'ve recently noticed that a function where I iterate over a DataFrame rows using .iloc is very slow. I found out that there\'s a faster method called

相关标签:
2条回答
  • 2021-02-14 06:38

    iat and at gives only a single value output, while iloc and loc can give multiple row output.
    Example:
    iloc[1:2,5:8] is valid but iat[1:2,5:8] will throw error

    0 讨论(0)
  • 2021-02-14 06:42

    iat and at working with scalar only, so very fast. Slower, more general functions are iloc and loc.

    You can check docs:

    Since indexing with [] must handle a lot of cases (single-label access, slicing, boolean indexing, etc.), it has a bit of overhead in order to figure out what you’re asking for. If you only want to access a scalar value, the fastest way is to use the at and iat methods, which are implemented on all of the data structures.

    Similarly to loc, at provides label based scalar lookups, while, iat provides integer based lookups analogously to iloc.

    0 讨论(0)
提交回复
热议问题