TGViewer
Big Data Science Big Data Science @bdscience · 3.56K subscribers
Post #498 582
🚀Pandas features: use at and iat in loops instead of iloc and loc
The Python-library Pandas has iloc and loc functions to access dateframe values by row index and index or column name. But running them inside loops is time consuming. If you replace loc with at, or iloc with iat, the execution time of a for loop can be reduced by a factor of 60!
Such a different difference in speed is due to the nature of these functions: at and iat include access to a scalar, that is, to one element of the dataframe. And loc and iloc are used for simultaneous access to elements (rows, dataframes), i.e. they are initially needed to perform vectorized operations.
Because of at/iat are used for accessing the scalar environment, they are faster than loc/iloc for serie/dataframe access and take more space and time. Therefore, using loc/iloc inside loops in Python is slow and should be replaced with at/iat, which exucute faster. However, loc and iloc work fine outside of Python loops for vectorized operations.
https://medium.com/codex/dont-use-loc-iloc-with-loops-in-python-instead-use-this-f9243289dde7
Medium Don’t use loc/iloc with Loops In Python, Instead, Use This! Run your loops at a 60X faster speed
  • 👍 6
More from @bdscience
  1. Nov 27, 2025💎 Imagen AI — an intelligent Adobe Lightroom assistant that automates photo editing by le…
  2. Oct 28, 2025🌐 OpenAI has released ChatGPT Atlas Atlas is a browser with an integrated AI sidebar, bui…
  3. Sep 16, 2025🤖 Nanobanana.ai is an AI aggregation platform that provides unified subscription-based ac…
  4. Jul 30, 2025🏀 Photoleap by Lightricks is a premier AI-powered image editing app that seamlessly blend…
  5. Jun 19, 2025⚙️ Rumi Labs transforms passive media into interactive entertainment A San Francisco-based…
  6. May 27, 2025📈Genspark AI: the autonomous super-agent for multi-step business workflows 🧠 Mixture-of-…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →