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
  • 34,416
  • 14
  • 83
  • 119
Hugo
  • 1,338
  • 12
  • 32
  • 63

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
  • 804
  • 4
  • 11