4

I've created a msgpack file from a Pandas Dataframe, using the following code:

df.to_msgpack('ixto.msg')

I've confirmed that the file is saved in the directory, but I can't use msgpack library for python since the following code:

unp = msgpack.unpackb('ixto.msg')

gives me the following error:

AttributeError: 'str' object has no attribute 'read'
chrisaycock
  • 36,470
  • 14
  • 88
  • 125
Hugo
  • 1,558
  • 12
  • 35
  • 68

1 Answers1

4

msgpack.unpackb expects bytes (thus the "b") containing encoded data, and you're giving it the name of the file containing the data.

So you need to read the file first :

with open('ixto.msg', 'rb') as f:
    unp = msgpack.unpackb(f.read())
kjaquier
  • 824
  • 4
  • 11