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.
example
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
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With