【发布时间】:2021-10-06 18:22:28
【问题描述】:
我有一个大约 25,000 行的大型数据集。我正在尝试为我的每一个观察结果提取高程数据。但是,我一次只能发出 100 个请求。这意味着我需要大约 250 次拆分来提出单独的请求!
我想知道是否有有效的方法来做到这一点?
我遇到了这种情况,但我不想重复这 250 次并每次都应用该函数。
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:]
以“粗略”的方式,这是我正在尝试的:
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
【问题讨论】:
-
df.loc[[i for i in range(df.shape[0]) if i%100==0]]如果数据框具有正常的数值范围索引值。
标签: python pandas dataframe for-loop split