基本上,以下代码返回另一个字符串中列'a'中字符的位置(在本例中为'} JKLMNOPQR')。在此示例中,列'b'在所有行中具有相同的值,但它可以具有不同的值。
有没有矢量化的方法来做到这一点?
frame = pd.DataFrame({'a' : ['L', '}', 'P']})
frame['b']='}JKLMNOPQR'
frame['c'] = frame.apply(lambda row: row.b.find(row.a), axis=1)
frame
a b c
0 L }JKLMNOPQR 3
1 } }JKLMNOPQR 0
2 P }JKLMNOPQR 7
答案 0 :(得分:3)
未使用select
min(Case tserv_id when 'Discharge' then PERFORMED end) as tserv_discharge,
min(Case tserv_id when 'ONPOWER' then PERFORMED end) as tserv_onpower --How to retrieve data performed between disharge & first onpower?
from
ODS_REEFER
where
EQ_NBR = 'A1234';
select
min(Case tserv_id when 'ONPOWER' then PERFORMED end) as tserv_onpower,
max(Case tserv_id when 'ONPOWER' then PERFORMED end) as tserv_onpower --How to exclude performed first ONPOWER and how to read performed between second ONPOWER?
from
ODS_REEFER
where
EQ_NBR = 'A1234';
进行矢量化,而是更快的解决方案:
zip
答案 1 :(得分:2)