DataFrame持久性错误的Pandas _metadata [英] Pandas _metadata of DataFrame persistence error

查看:355
本文介绍了DataFrame持久性错误的Pandas _metadata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于弄清楚了如何从DataFrame中使用_metadata,一切正常,除了我无法将其持久化,例如hdf5或json.我知道它是可行的,因为我复制了框架,而_metadata属性则复制到"non _metadata"属性上.

I have finally figured out how to use _metadata from a DataFrame, everything works except I am unable to persist it such as to hdf5 or json. I know it works because I copy the frame and _metadata attributes copy over "non _metadata" attributes don't.

示例

df = pandas.DataFrame #make up a frame to your liking
pandas.DataFrame._metadata = ["testmeta"]
df.testmeta = "testmetaval"
df.badmeta = "badmetaval"
newframe = df.copy()
newframe.testmeta -->outputs "testmetaval"
newframe.badmeta ---> raises attribute error

#json test
df.to_json(Path)
revivedjsonframe = pandas.io.json.read_json(Path)
revivedjsonframe.testmeta ---->raises Attribute Error

#hdf5 test
revivedhdf5frame.testmeta ---> returns None

此人 https://stackoverflow.com/a/25715719/4473236 说对他有用,但是我是该网站(和熊猫)的新手,因此无法发布到该主题或直接询问他.

this person https://stackoverflow.com/a/25715719/4473236 says it worked for him but I'm new to this site (and pandas) and can't post to that thread or ask him directly.

推荐答案

_metadata前面带有下划线,这意味着它不属于公共API.它不适合用于用户代码-我们可能会在将来的任何熊猫版本中都将其破坏,而不会发出警告.

_metadata is prefaced with an underscore, which means it's not part of the public API. It's not intended for user code -- we might break it in any future version of pandas without warning.

我强烈建议您不要使用此功能".目前,使用DataFrame持久保存元数据的最佳选择可能是编写自己的包装器类并自己处理持久性.

I would strongly recommend against using this "feature". For now, the best option for persisting metadata with a DataFrame is probably to write your own wrapper class and handle the persistence yourself.

这篇关于DataFrame持久性错误的Pandas _metadata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆