df[df.Service.str.match('CWS|Drive')]
Created UserID Service
0 1/1/2016 a CWS
2 3/5/2016 a Drive
其他口味 为了好玩!!
numpy-fi
^{pr2}$
添加numexpr
import numexpr as ne
s = df.Service.values
c1 = s == 'CWS'
c2 = s == 'Drive'
df[ne.evaluate('c1 | c2')]
时间 isin是赢家!str.match是输家:-(
np.random.seed([3,1415])
df = pd.DataFrame(dict(
Service=np.random.choice(['CWS', 'Drive', 'Other', 'Enhancement'], 100000)))
%timeit df[(df.Service == "CWS") | (df.Service == "Drive")]
%timeit df[df.Service.isin(["CWS", "Drive"])]
%timeit df.query('Service == "CWS" | Service == "Drive"')
%timeit df.query('Service == ["Other", "Drive"]')
%timeit df.query('Service in ["Other", "Drive"]')
%timeit df[df.Service.str.match('CWS|Drive')]
100 loops, best of 3: 16.7 ms per loop
100 loops, best of 3: 4.46 ms per loop
100 loops, best of 3: 7.74 ms per loop
100 loops, best of 3: 5.77 ms per loop
100 loops, best of 3: 5.69 ms per loop
10 loops, best of 3: 67.3 ms per loop
%%timeit
s = df.Service.values
c1 = s == 'CWS'
c2 = s == 'Drive'
df[c1 | c2]
100 loops, best of 3: 5.47 ms per loop
%%timeit
import numexpr as ne
s = df.Service.values
c1 = s == 'CWS'
c2 = s == 'Drive'
df[ne.evaluate('c1 | c2')]
100 loops, best of 3: 5.65 ms per loop
需要按位比较
|
(or
):最好是使用^{} :
^{pr2}$或使用^{} :
或^{} with ^{} :
您也可以使用
pandas.Series.str.match
其他口味
为了好玩!!
^{pr2}$numpy
-fi添加
numexpr
时间
isin
是赢家!str.match
是输家:-(相关问题 更多 >
编程相关推荐