Hi guys,
I have a dataframe that I use to create a similarity matrix, but I canāt change the name of my columns once my matrix is generated. My code runs fine in Python Notebook but for some reason it wonāt work when I try to run it in Streamlit. I was able to change manually the name of the first columns, but my dataframe has 4111 columns in total, so Iām trying to find a way to automate the process.
Hereās my code:
#import of my original dataset
dfm = pd.read_csv(ādf_matrix.csvā, index_col = āartist_trackā)
st.dataframe(dfm)
#initiation of column names through a list:
new_index = list(dfm.index)
#creation of maxtrix:
pairwise = pd.DataFrame(squareform(pdist(dfm, āmahalanobisā)), columns = new_index)
st.dataframe(pairwise)
I tried changing the index values instead, which worked:
new_index = list(dfm.index)
pairwise = pd.DataFrame(squareform(pdist(dfm, āmahalanobisā)), index = new_index)
st.dataframe(pairwise)
But then when I try to transpose the dataframe, I get the same error:
new_index = list(dfm.index)
pairwise = pd.DataFrame(squareform(pdist(dfm, āmahalanobisā)), index = new_index).T
st.dataframe(pairwise)
I tried changing the columns names using a dictionary but it didnāt work either:
new_index = list(dfm.index)
col_index = np.arange(0,4112)
index = dict(zip(col_index, new_index))
pairwise = pd.DataFrame(squareform(pdist(dfm, āmahalanobisā)))
pairwise = pairwise.rename(columns = index)
st.dataframe(pairwise)
I know I must be missing something somewhere, but I donāt what it is.
Thanks for your help!