Skip to content
Advertisement

Dataframe row slicing is not consistent

I have a DataFrame variable called data with ~ 6 mil rows and I’d like to process it 50 rows at a time. I have the following code:

JavaScript

However it seems the slices obtained are not 50 rows in length. In fact they seem to be random (although every time I re-run the program they stay consistent. The first one is always 34, then always 48 etc …). Here is a sample output:

JavaScript

Is this an expected behavior from the DataFrame class?

Advertisement

Answer

enter image description here

That’s what happens when you use loc. And that’s what happens when you use iloc:

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement