0

Hi all this is my first time posting here and my first time attempting to write Python so bear with the minimal knowledge I have!

I am building this out within Alteryx and below is a screenshot of the "manual" join that the Alteryx flow currently uses.enter image description here

So, the goal in my python script is to take data from input stream (#1) and append it to specific records in input stream (#2) where the column headers match (this part is important because the column headers could be different every time that are coming in from input #1). Additionally, I need to bring in a field called "Personnel Name" from input stream #1. So the desired end state would maintain all the records from input steam #1 but would add the field "Personnel Name" where a match is found (the match coming from a dynamic join).

So far, I was able to append the data dynamically, but it is not appending to specific records. Here is the code I have used that gave me that end result:

#Get the Alteryx engine and the Alteryx inputs
input1 = Alteryx.read("#1")
input2 = Alteryx.read("#2")

#Load the data streams as a Pandas DataFrame
df1 = pd.DataFrame.from_records(input1)
df2 = pd.DataFrame.from_records(input2)

#Get a list of column headers from both data streams
headers1 = list(df1.columns)
headers2 = list(df2.columns)

#Find the column headers that are present in both data streams
common_headers = list(set(headers1) & set(headers2))

#Append the rows from the second data stream to the first data stream where the column headers match
df2 = pd.concat([df2, df1.loc[:, common_headers]], axis=0, ignore_index=True)

#Convert the merged data stream back to an Alteryx output
output = pd.DataFrame.to_records(df2)

#Write the merged data stream to an Alteryx output
Alteryx.write(df2,1)
llcode97
  • 1
  • 1

0 Answers0