Different Ways to Iterate Over Rows in Pandas DataFrame | GeeksforGeeks

Different Ways to Iterate Over Rows in Pandas DataFrame | GeeksforGeeks

GeeksforGeeks

3 года назад

46,054 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Dora Pomaa
Dora Pomaa - 18.08.2023 00:08

Please I can't see the fonts clearly

Ответить
Max Max
Max Max - 09.07.2023 16:07

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.

Ответить
Naajid Sarosh
Naajid Sarosh - 02.10.2022 00:20

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

Ответить
Kishore P
Kishore P - 08.09.2022 20:25

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

Ответить
Mansingh Chauhan
Mansingh Chauhan - 03.08.2022 18:51

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.

Ответить
Drew Levitt
Drew Levitt - 19.05.2022 17:36

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.

Ответить
John Wheeler
John Wheeler - 15.05.2022 01:51

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

Ответить
Murali AxonifyTech
Murali AxonifyTech - 23.03.2022 16:10

super

Ответить
LIE: MOTIVATION
LIE: MOTIVATION - 13.07.2021 21:26

Hi

Ответить