0

I was using the tool asammdf and realized that my DataFrame contains b-strings. I never heard and used that type of string before, however it is causing some problems with my other functions.

Do you know if there is a efficient way to convert my pandas dataframe? Or some other solutions?

The DataFrame looks something like:

column1   column2 ...
b'7.00'   b'21.0' ...
b'8.00'   b'22.0' ...
...       ...

The DataFrame is being created from asammdf with

asammdf.mdf.MDF.to_dataframe() 

I just choose the channels and groups and usually it creates a perfect DataFrame.

Thank you very much in advance for your help!

So far I tried to store each series astype('float64') in order to calculate with my values.

tlets
  • 1
  • 1
  • Hi! can you give us an exaple of your dataframe? And some code that you tried to use? – DonPre Nov 10 '22 at 16:10
  • You can try to use something like `df[0] = df[0].astype(float)` for each column – DonPre Nov 10 '22 at 16:35
  • I tried that, but I don't want anything to be a float. I just want to get rid of the b'x', that would be perfect... – tlets Nov 11 '22 at 07:19
  • The `b'x'` is just a way that python use to tell you that the data is store in bytes, so if you need to get rid of the `b` is to convert (decode is the right term) your values. So if you want them to be string you need to `df[0] = df[0].astype(string)` or whatever type you need. If you need more information about the bytestrings you can take a look at [this question](https://stackoverflow.com/questions/6224052/what-is-the-difference-between-a-string-and-a-byte-string) – DonPre Nov 11 '22 at 07:32
  • Okay! But there is no way, I can decode the whole DataFrame at once? Because my case contains each float and string within the DataFrame. Thanks for the similar post! – tlets Nov 11 '22 at 07:57
  • Take a look at [this](https://stackoverflow.com/questions/40389764/how-to-translate-bytes-objects-into-literal-strings-in-pandas-dataframe-pytho) – DonPre Nov 11 '22 at 08:02

0 Answers0