【问题标题】:Python - Read msgpack file and store it to the Data FramePython - 读取 msgpack 文件并将其存储到数据框中
【发布时间】:2018-08-23 19:48:20
【问题描述】:
def df_to_msgpack(df, filename):
df.to_msgpack(filename, default=decimal_default)

上面的函数将 DF 存储到 messagepack 文件中。现在,我想读取文件并将其存储在 DF 中以供进一步计算。怎么办?

    with open(filename, 'rb') as data_file:
    data_loaded = msgpack.unpackb(data_file.read())

我尝试了上面的解决方案,但没有帮助。

msgpack_read(filename)

解决方案也只读取文件。有什么解决办法吗?

【问题讨论】:

    标签: python python-3.x pandas dataframe msgpack


    【解决方案1】:

    您可以使用pandas.read_msgpack,尽管它仍然是ver0.23.4 中的experimental version

    df = pd.read_msgpack(filename)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-26
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2017-06-25
      • 1970-01-01
      相关资源
      最近更新 更多