简体   繁体   中英

How do I convert multiple digits to ASCII?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM