0

I have a dataset where all the numeric variable values are appearing in b'123' byte object form.

I tried the following code: df['var'].str.decode('utf-8') But the var becomes NaN for all the data points.

How do I get rid of the b'' from b'123' variable value. My variable types show type object but I need numeric value?

Legorooj
  • 2,646
  • 2
  • 15
  • 35
Meheli
  • 1
  • 2

1 Answers1

0

You could try:

df['var'] = df['var'].decode('utf-8')
Legorooj
  • 2,646
  • 2
  • 15
  • 35
  • Hi thank you for your response... I tried this but get the following error: Attribute error: 'Series' object has no attribute 'decode'. – Meheli Feb 01 '19 at 02:38
  • Mabye have a look at these two links, they might be of help: https://stackoverflow.com/questions/40389764/how-to-translate-bytes-objects-into-literal-strings-in-pandas-dataframe-pytho and http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.decode.html – Legorooj Feb 01 '19 at 12:23
  • Hi again! Did my last comment help? – Legorooj Feb 06 '19 at 16:27
  • Hi... actually it did not work... I think I have some crazy variable types... but thanks anyways :-) – Meheli May 14 '19 at 01:06
  • Hmm. Mabye try replacing the `utf-8` with `ansi` or another bytecode format. – Legorooj May 14 '19 at 09:34