Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing all user-created metadata of a pandas Series #17480

Closed
jondoesntgit opened this issue Sep 8, 2017 · 2 comments
Closed

Accessing all user-created metadata of a pandas Series #17480

jondoesntgit opened this issue Sep 8, 2017 · 2 comments
Labels
Duplicate Report Duplicate issue or pull request Internals Related to non-user accessible pandas implementation

Comments

@jondoesntgit
Copy link

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

@gfyoung gfyoung added the Internals Related to non-user accessible pandas implementation label Sep 9, 2017
@gfyoung
Copy link
Member

gfyoung commented Sep 9, 2017

@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...

@jreback
Copy link
Contributor

jreback commented Sep 9, 2017

#8572

@jreback jreback closed this as completed Sep 9, 2017
@jreback jreback added the Duplicate Report Duplicate issue or pull request label Sep 9, 2017
@jreback jreback added this to the No action milestone Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Internals Related to non-user accessible pandas implementation
Projects
None yet
Development

No branches or pull requests

3 participants