I’m iterating a dataframe with the following code:
JavaScript
x
13
13
1
print(access_df)
2
3
Out:
4
ActionAccess Arn
5
0 s3:* a--
6
1 xray:PutTele b--
7
2 s3:*MultipartUpload* c--
8
3 xray:GetSamplingTargets d--
9
10
for index, row in access_df.iterrows():
11
if 's3:*' in row['ActionAccess']:
12
print(row)
13
I’m trying to get values that are only s3:*
. However the above code also detects cases such as s3:*Object
and s3:*MultipartUpload*
.
How do I define the if statement to only get values that contain only s3:*
?
Advertisement
Answer
Not sure if I really understand the question, but if you just want to check whether the string is literally 's3:*'
, i.e. the *
is not supposed to be some kind of placeholder/wildcard, just use ==
:
JavaScript
1
2
1
if 's3:*' == row['ActionAccess']:
2
If you are looking for 's3:*'
(but not 's3:*stuff*'
) as part of a larger string, e.g. "some string with s3:* inside"
, then you might use str.split
or resort to a regular expression.