zyhuang 最近的时间轴更新
zyhuang

zyhuang

V2EX 第 246845 号会员,加入于 2017-08-04 18:35:32 +08:00
zyhuang 最近回复了
2018-01-12 09:54:56 +08:00
回复了 w12103 创建的主题 Python pandas 代码请教
```
import pandas as pd
import numpy as np

won_last = pd.DataFrame({'lastwin':["lastwin_{}".format(i) for i in range(10000)]})
dset = pd.DataFrame(np.random.randint(10000, size=(10000, 2)),
columns=['home', 'visitor'])
In [2]:
%timeit dset.merge(won_last, left_on='home', right_index=True,how='left').merge(won_last, left_on='visitor', right_index=True,how='left', suffixes="hv")

7.16 ms ± 340 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)


In [3]:
%timeit dset.assign(hlastwin=lambda x: [won_last.lastwin[ii] for ii in x.home], vlastwin=lambda x: [won_last.lastwin[ii] for ii in x.visitor])
355 ms ± 34.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

```
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1241 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 18:16 · PVG 02:16 · LAX 10:16 · JFK 13:16
Developed with CodeLauncher
♥ Do have faith in what you're doing.