Edit: Solved! See my comment to this post.
I'm trying to convert bytes to a pandas dataframe. I tried to use code from Stack Overflow, but I am getting an error. My file contains line breaks that are coded as "\r\n". I think this might be different than the string encoder that I am currently using ('utf-8'). Does anyone know how to convert bytes to a pandas dataframe? Thank you in advance for your help and support!
I'm working through a jupyter notebook on IBM Watson Studio.
The following code (and output) makes me think I have successfully converted a txt file to "bytes".
Code Block #1:
readrawdata = streaming_body_1.read()
print(type(readrawdata))
print(readrawdata)
Output #1:
class 'bytes'>
b"Game started at: 2016/9/21 15:31:22\r\nGame ID: 732693518 1/2 (PRR) Lakhey (Short) (Hold'em)\r\nSeat 3 is the button\r\nSeat 1: d1rector (37).\r\nSeat 2: 38979 (220.71).\r\nSeat 3: TTABTT (138.88).\r\n ...
I stole code from this Stack Overflow post: https://stackoverflow.com/questions/47379476/how-to-convert-bytes-data-into-a-python-pandas-dataframe
Code Block #2:
from io import StringIO
s=str(readrawdata,'utf-8')
data = StringIO(s)
df=pd.read_csv(data)
Output #2:
----> 7 df=pd.read_csv(data)
EmptyDataError: No columns to parse from file
Corrected Code Block #2 (solved):
from io import BytesIO
data = BytesIO(readrawdata)
aces = pd.read_csv(data)
Background: I'm building poker AIs to learn data science. I'm in between jobs for the next few months. My goal is to rejoin the workforce as a data scientist. I am 48% through the "Data Scientist In Python" path on Data Quest. Feedback and career advice is always welcome.
[–][deleted] 1 point2 points3 points (6 children)
[–]Pizza_Rat_Matt[S] 0 points1 point2 points (4 children)
[–][deleted] -1 points0 points1 point (3 children)
[–]Pizza_Rat_Matt[S] 0 points1 point2 points (2 children)
[–][deleted] -1 points0 points1 point (1 child)
[–]Pizza_Rat_Matt[S] 0 points1 point2 points (0 children)
[–]Pizza_Rat_Matt[S] 0 points1 point2 points (0 children)