[Solved] Python: Apply function every 100 rows of large dataframe

Joehat Asks: Python: Apply function every 100 rows of large dataframe
I have a large dataset of approximately 25,000 rows. I am trying to extract elevation data for every one of my observations. However, I can only make 100 requests at a time. This means that I need approximately 250 splits to make individual requests!

I was wondering if there is an efficient way of doing this?

I came across this condition but I wouldn’t want to repeat this 250 times and apply the function each time.

first_hun = pd.DataFrame()
rest = pd.DataFrame()

if df.shape[0] > 100: # len(df) > 100 would also work
    first_hun = df[:100]
    rest = df[100:]

In a “sketchy” way, this is what I am attempting:

for index,row in df.iterrows():
    # split df every 100 rows
        # apply elevation function (my_function)
        # store the 100 elevation values
    # concat the 250 elevation values so they're in the same list
# add list to original df

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.