如何使pandas str.contains(不必以开头)连续查询2个字母

How to make pandas str.contains (don't have to be starts with) query 2 letter consecutively

这是我的数据集

Id sitename
1  BERASAMA
2  LTE_RS_HARAPAN
3  RSA_IBU
4  OFFICE

这是我的代码

filter = df[df['sitename'].str.contains("RS")]

我的期望

Id sitename
2  LTE_RS_HARAPAN
3  RSA_IBU

现实

Id sitename
1  BERASAMA
2  LTE_RS_HARAPAN
3  RSA_IBU

我知道“BERASAMA”包含 RS 而不是连续

我想你在找 str.startswith:

out = df[df['sitename'].str.startswith("RS")]

输出:

   Id    sitename
1   2     RS_HARAPAN
2   3     RSA_IBU