I'm using python 2.7 and I have a dataframe with greek letters writen like this:
units = ['Ab_alpha_cd', 'XY_beta_zz', 'Ef_gamma_gh']
descriptions = ['Name1 (Ab_alpha_cd): description_1', 'Name2 (XY_beta_zz): description_2', 'Name3 (Ef_gamma_gh): description_3'
df = pd.dataframe
df['units'] = units
df['descriptions'] = descriptions
What I need is to change the '_greek_'
in the descriptions column to the correct greek letters.
I have tried several ways:
#first try:
for i in range (0, len(df)):
df.loc[i,'descriptions'].replace('_alfa_','\u03B1').replace('_beta_','\u03B2').replace('_gamma_','\u03B3')
#second try:
for i in range (0, len(df)):
df.loc[i,'descriptions'].replace('_alfa_',unichr(945)).replace('_beta_',unichr(946)).replace('_gamma_',unichr(947))
#thrid try
for i in range (0, len(df)):
df.loc[i,'descriptions'].replace('_alfa_','α').replace('_beta_','β').replace('_gamma_','γ')
#fourth try
for i in range (0, len(df)):
df.loc[i,'descriptions'].replace('_alfa_','α'.encode('utf-8')).replace('_beta_','β'.encode('utf-8')).replace('_gamma_','γ'.encode('utf-8'))
But nothing really worked. When I call df.head()
, the greek letters do not show. They also do not show when I try wrinting the df to a csv file, even using utf-8 enconding.
I need the final result to be a list with the strings corrected.
What could I do?