Dynamic Expression Evaluation in pandas using pd.eval()

前端 未结 2 1468
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 06:30

Given two DataFrames

np.random.seed(0)
df1 = pd.DataFrame(np.random.choice(10, (5, 4)), columns=list(\'ABCD\'))
df2 = pd.DataFrame(np.random.choice(10, (5,          


        
2条回答
  •  孤街浪徒
    2020-11-22 07:21

    Great tutorial already, but bear in mind that before jumping wildly into the usage of eval/query attracted by its simpler syntax, it has severe performance issues if your dataset has less than 15,000 rows.

    In that case, simply use df.loc[mask1, mask2].

    Refer: https://pandas.pydata.org/pandas-docs/version/0.22/enhancingperf.html#enhancingperf-eval

提交回复
热议问题