0

How do i convert all of the values in this dataframe to ASCII?

I have split a string to individual characters (shown below), and now i would like to convert the values in that data frame to ASCII.

play1 = accounts['Identifier'].dropna()\
        .apply(lambda x: pd.Series(list(x))).add_prefix('id_')

which produced the below dataframe:

  id_0  id_1  id_2  id_3  id_4  id_5
0  2     7    6     2     2     Nan
1  4     9    8     4     4     6
2  7     6    7     3     Nan   Nan

Now i want to convert all of the values in id_ to ASCII.

I have tried using ord() function:

play2 = play1.columns\
        .apply(lambda x: pd.Series(ord(x)))
play2.head()

But it does not work. Please assist

Mbali_c
  • 47
  • 6

1 Answers1

0

Use list comprehension:

play1 = pd.DataFrame([[ord(y) for y in list(x)] 
                      for x in accounts['Identifier'].dropna()]).add_prefix('id_')
print (play1)
   id_0  id_1  id_2  id_3  id_4  id_5
0    50    55    54    50  50.0   NaN
1    52    57    56    52  52.0  54.0
2    55    54    55    51   NaN   NaN
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252