My goal is to transform the following contents of File1 and File2 columns of my dataframe named 'concatenated':
concatenated
File1 File2 Frequency
Cambo_1.csv Cambo_2.csv 3
Cambo_1.csv Cambo_3.csv 2
Cambo_2.csv Cambo_4.csv 1
Cambo_2.csv Cambo_5.csv 5
into the following format:
dataframe
Cambo_1 Cambo_2 Cambo_3 Cambo_4 Cambo_5
Cambo_1 NA 3 2 NA NA
Cambo_2 NA NA NA 1 5
Cambo_3 NA NA NA NA NA
The format looks like a correlation table. The only difference is that File1 should appear in the row part of the new dataframe, and File2 on the column part of the dataframe. If they are interchanged, "NA" value will appear. Also, take note that ".csv" is already disregarded on the newly formatted dataframe.
I am new to programming and in python, anyway my code looks like this:
for i in dataframe.iterrows():
if re.match(dataframe.loc[i,].astype(str))==re.match(concatenated_ans2['0'].astype(str)) and re.match(dataframe.loc[:,i].astype(str))==re.match(concatenated_ans2['1'].astype(str)):
dataframe.at[rows,columns] = concatenated_ans2['2']
else dataframe.at[rows,columns] = 'NA'
But I got this error:
ValueError: Location based indexing can only have [integer, integer slice (START point is INCLUDED, END point is EXCLUDED), listlike of integers, boolean array] types
Anyone willing to help?