Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Write bytes data into a data frame

I scraped one site and I get the data in bytes and I do not know how I can write them into a DF in some efficient way.

Here is a piece of my data:

b'[{"ID":"1","A":"2021-08-04 11:00:00","B":"2021-08-05 10:52:30","C":"","D":"2021-08-05 10:51:00","E":"","F":"Mark","G":"","H":"BOSTON"}]'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your problem is not how to transform bytes into a df, but how to transform bytes into a data structure that is "friendly" to df.

"eval" will try to transform the string/bytes into a data structure; in this case: a list of dictionaries

pd.DataFrame(eval(a), columns=eval(a)[0].keys())

note: if the bytes are valid jsons, its more efficient to use "json.loads" instead of "eval"

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading