I'm iterating a dataframe and trying to append new values inside from a different dataframe whenever a row in the first dataframe is a certain value.
Consider the following two dataframes:
print(full_df)
AccessName PolicyArn
0 arn:aws:glue:sample arn:aws:iam::971340810992:policy/service-role/...
1 arn:aws:glue:sample2 arn:aws:iam::971340810992:policy/service-role/...
2 --- arn:aws:iam::971340810992:policy/service-role/...
3 arn:aws:s3:::sample3 arn:aws:iam::971340810992:policy/service-role/...
print(side_df)
AccessName
0 sample-test
1 query_sample
2 us-east-1-sample
If the AccessName in the full_df is a certain value, the side_df is appended to the full_df, having the second row value always be arn for all rows.
arn = 'fixed_value'
for index, row in full_df.iterrows():
if row['AccessName'] == '---':
#Here I don't know how I'd define the code to append the side_df values:
#full_df['AccessName'] = side_df['AccessName']
#full_df['PolicyArn'] = arn
Would it be best to make another if statement at that point and iterate the side_df values and append row by row?
This for function is nested in the actual code and the arn is dynamically generated.
Desired output:
AccessName PolicyArn
0 arn:aws:glue:sample arn:aws:iam::971340810992:policy/service-role/...
1 arn:aws:glue:sample2 arn:aws:iam::971340810992:policy/service-role/...
2 --- arn:aws:iam::971340810992:policy/service-role/...
3 sample-test fixed_value
4 query_sample fixed_value
5 us-east-1-sample fixed_value
6 arn:aws:s3:::sample3 arn:aws:iam::971340810992:policy/service-role/...
What would be the optimal way to code this?