Answers for "r loop over each row in dataframe shp"

41

pandas loop through rows

for index, row in df.iterrows():
    print(row['c1'], row['c2'])

Output: 
   10 100
   11 110
   12 120
Posted by: Guest on February-23-2020
0

pandas loop over chunk of rows

# credit to Stack Overflow user in the source link
import numpy as np
import pandas as pd

data = pd.DataFrame(np.random.rand(10, 3))
for chunk in np.array_split(data, 5):
  # this assert may not be needed depending on your application
  # left here anyway because it is in the original answer
  assert len(chunk) == len(data) / 5, "This assert may fail for the last chunk if data lenght isn't divisible by 5"
  # do your stuff with each chunk
Posted by: Guest on November-15-2021

Code answers related to "r loop over each row in dataframe shp"

Python Answers by Framework

Browse Popular Code Answers by Language