【发布时间】:2021-04-24 19:36:56
【问题描述】:
我想在一定的区间内改变数据集中的目标值。当使用 500 个数据时,大约需要 1.5 秒,但我有大约 100000 个数据。大部分执行时间都花在了这个过程中。我想加快速度。
What is the fastest and most efficient way to append rows to a DataFrame? 我尝试了此链接中的解决方案,尝试创建字典,但我做不到。
这是 500 条数据大约需要 1.5 秒的代码。
def add_new(df,base,interval):
df_appended = pd.DataFrame()
np.random.seed(5)
s = np.random.normal(base,interval/3,4)
s = np.append(s,base)
for i in range(0,5):
df_new = df
df_new["DeltaG"] = s[i]
df_appended = df_appended.append(df_new)
return df_appended
【问题讨论】:
标签: python dataframe dictionary