0

enter image description hereI'm using sns.clustermap to plot a dataframe from a panda dataframe. I want to replace all the instances of "alpha" and "beta" to the lowercase latin letters, but I can't do it nomatter how I try. I tried to code it in Latex. Here is an example code:

df = pd.DataFrame(data = [[1, 2], [3, 4]], index = ['5alpha-androstan-3beta,17alpha-diol disulfate', 'hippurate'])
df.index = df.iloc[:,0].index.str.replace('alpha', '$\alpha')
sns.clustermap(df)

Thanks!

user1748101
  • 275
  • 1
  • 3
  • 9

2 Answers2

0

Doing with dict passing to replace

df.index=df.index.to_series().replace({'alpha':'α',"beta":'β'},regex=True)
df
Out[664]: 
                                    0  1
5α-androstan-3β,17α-diol disulfate  1  2
hippurate                           3  4
BENY
  • 317,841
  • 20
  • 164
  • 234
0

So Now this works:

df = pd.DataFrame(data = [[1, 2], [3, 4]], index = ['5alpha-androstan-3beta,17alpha-diol disulfate', 'hippurate'])
df.index=df.index.to_series().replace({'alpha':'α',"beta":'β'},regex=True)
df

But I get the following error from clustermap:

"UnicodeDecodeError: 'ascii' codec can't decode byte 0xce in position 24: ordinal not in range(128)"

user1748101
  • 275
  • 1
  • 3
  • 9