I want to match between indexes of rows in two different dfs, and if the indexes are the same, I want to go to the second df, iterate through it's columns, and if the value of a column is 'V', go to the first df, and add the name of the df to the value of a column.
so for example:
MAIN DF:
names col1 col2 col3 total
bbb V V X 2
ccc V X X 1
DF2:
names col1 col2 col3 total
bbb V V X 2
zzz X X V 1
so after the MAIN DF will be:
names col1 col2 col3 total totla_col1 total_col2 total_col3
bbb V V X 2 DF2 DF2 NULL
ccc V X X 1 NULL NULL NULL
解决方案
You can first create index from names column by set_index, replace values by dict and add_prefix.
Then join it to original:
cols = ['col1','col2','col3']
DF2 = DF2.set_