ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.

Replicating Python For Loop

wonka1234
10 - Fireball

Hi all,
 
I am trying to replicate the following functionality with alteryx:
 
column_list = pd.DataFrame(['Col1','Col2','Col3','Col4', 'Col5',
'Col6','Col7','Col8','Col9','Col10',
'Col11','Col12'])

final_hr = pd.DataFrame()
 
for column in range(len(column_list)):
           hr_new=hr.copy()

          #Drop rows containing NAN for column 'col4' for new merge
          hr_new.dropna(subset=[column_list.iloc[column,0]], inplace = True)

          #Creating a new column for merge
           hr_new['ID_final']=hr_new[column_list.iloc[column,0]]

           #case folding
           hr_new['ID_final']=hr_new['ID_final'].str.strip().str.upper()

           #Merge data
          merged_data = pd.merge(hr_new, data, how='left', left_on='ID_final', right_on ='OtherID')

           #Concatinating all data together
            final_hr = final_hr.append(merged_data)
 

 
my thinking on the logic: For each iteration of the loop, it's taking each of the user ID fields(Col1 to Col 12) and writing that to the ID_final field. And then it tries to use that to join to "data". Then appends everything to final_hr dataframe.

 

What I have trouble replicating is the loop and writing that to an "ID_final" field , aswell as the  final_hr.append part, not sure what this is exactly doing.

 

Any help would be appreciated.

2 REPLIES 2
JarekSkudrzyk
11 - Bolide

@wonka1234 

hi, I am not sure if I understood you correctly. Could you please share inputs and expected results?

 

ArtApa
Alteryx
Alteryx

Hi @wonka1234 - I think you may want to investigate Iterative Macros in Alteryx: https://community.alteryx.com/t5/Interactive-Lessons/tkb-p/interactive-lessons/label-name/Macros 

Labels
Top Solution Authors