Different Ways to Iterate Over Rows in Pandas DataFrame | GeeksforGeeks

preview_player
Показать описание
In this video, we're going to discuss how to iterate over rows in Pandas DataFrame with the help of live examples. There are various ways to do the same like using index attribute, loc[] function, iloc[] function, etc. So, let's get started now.

Check Out the Related Articles:

00:00 Let's Start
01:06 Iterating Over the Rows Using index method
02:53 Iterating Over the Rows Using loc[] method
04:28 Iterating Over the Rows Using iloc[] method
05:47 Iterating Over the Rows Using iterrows() method
06:57 Iterating Over the Rows Using itertuples() method
08:09 Iterating Over the Rows Using apply() method
09:09 Closing Notes

This video is contributed by Akshit Madan.
Please Like, Comment, and Share the Video with your friends.

#python​​ #pandas​​ #geeksforgeeks #dataframe​​ #datascience​​ #pythonpandas​​ #eda​​

Install our Android App:

If you wish, translate into the local language and help us reach millions of other geeks:

Follow us on our Social Media Handles -

Also, Subscribe if you haven't already! :)
Рекомендации по теме
Комментарии
Автор

This video helped a lot, it was my first day trying panda, i am no expert but as a beginners I think this is very useful.

mansinghchauhan
Автор

Someone mentioned using Vectorize, but I kind of think using Vectorize might not be good for large DataFrame's because of the overhead of converting a DF into a numpy array. Not tested yet.

maxmax
Автор

This is useful but you haven’t answered the fundamental question of when I should use each method! Which is most efficient?

johngwheeler
Автор

So many problems with this video. One big one is that you never explain WHY you would want to iterate over the rows of a DF - but even bigger than that is that you never explain that you usually SHOULDN'T loop over the rows! It is WAY slower to iterate over rows than to do columnar (vectorized) operations, and indeed, learning to think in vectorized steps is a key to getting good at pandas.

Then there are sloppy details... for instance, in the .loc section, you iterate over range(len(df)) instead of df.index. This only works in your example because df happens to have a RangeIndex. To be safe with .loc, you should iterate over df.index itself, or else use .iloc if you're going to iterate over a range.

I suppose for someone getting started with pandas, this video could be helpful insofar as it shows the basic syntax and options for row-wise operations, but you are doing that inexperienced viewer a disservice by failing to discuss the WHY and the WHY NOT around the whole topic.

DrewLevitt
Автор

Lambda is the fastest method? Can we get multiple columns using Lambda method?

kishorep
Автор

Bro, in the 2nd method you can just write df.loc(index, ['col1', 'col2', 'col3']) rather than writing df.loc again and again

naajidsarosh
Автор

Please I can't see the fonts clearly

dorapomaa
Автор

2nd method me loc index data use krta he iss example me index range tha nahi toh error aata meri csv file me index datetime object tha isliye error aaya 2nd example me df.index use krna tha loop me Not a proper video and explaination

Purity