0

I am currently using the Numpy package (version 1.12.1) in Spyder (Python 3.6). For some reason I am unable to remove 'b's which appear before strings in the IPython Console.

   import numpy as np

   student = np.dtype([('name', 'S20'), ('age', 'i1'), ('code', 'i4')])
   print (student)

   recordsvar = np.array([('Cordelia',28,100),('Cordelia',29,101),
   ('Cordelia',30,102)], dtype=student)
   print (recordsvar)

The output is

[(b'Cordelia', 28, 100) (b'Cordelia', 29, 101) (b'Cordelia', 30, 102)]

How do I remove the 'b' in from of Cordelia?

Thanks in advance

cordelia
  • 133
  • 3
  • 12

1 Answers1

3

The b' indicates, that your data is stored as bytes, the numpy datatype is S20. If you want to store characters, use unicode as datatype: U20:

student = np.dtype([('name', 'U20'), ('age', 'i1'), ('code', 'i4')])
Daniel
  • 42,087
  • 4
  • 55
  • 81