Code Sample, a copy-pastable example if possible
import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(10))
s.foo = 'bar'
print(s.__dict__)
Problem description
I heard on SO that there was some sort of metadata
field. I was not able to figure out how to work with this.
On the other hand, I was able to access metadata through the __dict__
attribute. However, I got lots of other properties as well. I could write something like
def get_metadata(series):
tmp_dict = dict()
for key in s.__dict__:
if key.startswith('_'):
continue
if key == "is_copy":
continue
tmp_dict[key] = s.__dict__[key]
return tmp_dict
get_metadata(s)
But it seems like this is something that could ship with pandas out of the box.
Expected Output
This is what I'm currently getting
{'foo': 'bar', '_item_cache': {}, '_name': None, '_data': SingleBlockManager
Items: RangeIndex(start=0, stop=10, step=1)
FloatBlock: 10 dtype: float64, 'is_copy': None, '_index': RangeIndex(start=0, stop=10, step=1), '_subtyp': 'series'}
This is what I'd like to see, perhaps through another function. (metadata
?)
{'foo': 'bar'}
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Darwin
OS-release: 15.6.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
pandas: 0.19.1
nose: None
pip: 9.0.1
setuptools: 36.2.7
Cython: None
numpy: 1.11.2
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.6.2
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0b10
httplib2: 0.10.3
apiclient: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
boto: None
pandas_datareader: None
Comment From: gfyoung
@jreback : I feel like there is an issue where this discussion is already going on with regards to metadata for pandas
objects, but I don't quite remember which...
Comment From: jreback
https://github.com/pandas-dev/pandas/issues/8572