Skip to content

Series to_string does not show index name #5734

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

Closed
cancan101 opened this issue Dec 18, 2013 · 12 comments
Closed

Series to_string does not show index name #5734

cancan101 opened this issue Dec 18, 2013 · 12 comments

Comments

@cancan101
Copy link
Contributor

The standard repr for a Series shows the index name:

repr(pd.Series([1], index=pd.Index(["a"], name="idx")))
idx
a      1
dtype: int64

but to_string does not:

pd.Series([1], index=pd.Index(["a"], name="idx")).to_string(name=True)
a      1
@jreback
Copy link
Contributor

jreback commented Dec 18, 2013

I believe it was designed this way and is not a bug

@cancan101
Copy link
Contributor Author

Any reason to not at least have a parameter for to_string to print the index name?

@jreback
Copy link
Contributor

jreback commented Dec 18, 2013

what is the use case?

@dsm054
Copy link
Contributor

dsm054 commented Dec 18, 2013

Aside: the parameter names floating around there could be much more informative. I couldn't figure out if there was a names/name typo here or not.

        if is_multi:
            have_header = any(name for name in index.names)
            fmt_index = index.format(names=True)
        else:
            have_header = index.name is not None
            fmt_index = index.format(name=True)

@cancan101
Copy link
Contributor Author

The biggest use case is in the case of a multiindex where having the labels on the various indexes is very helpful.

@jreback
Copy link
Contributor

jreback commented Dec 18, 2013

their is an open issue about repr for mi

why don't u add this their as that's a more appropriate context

@jtratner
Copy link
Contributor

@dsm054 - that could actually be refractored to just refer to names now (feel free to submit a PR - I'll turn it around quickly 😄). Unifying the Index API such that regular Index is just a single level MI is planned for 0.14, the name/names distinction is to enable more intuitive (and backwards compatible) syntax when setting the name of regular Index.

@cancan101
Copy link
Contributor Author

@jreback Which open issue are you referring to?

@jreback
Copy link
Contributor

jreback commented Dec 20, 2013

related to #5120
iIIRC

@cancan101
Copy link
Contributor Author

@jreback That issue is closed and I don't think the fix addressed this specific issue.

@jreback
Copy link
Contributor

jreback commented Dec 21, 2013

this belongs as an enhancement in a displaying a multi index not as a standalone
I'll leave u to figure out which one

@jreback
Copy link
Contributor

jreback commented Apr 14, 2015

This is already possible in master (IIRC recently fixed though)

In [12]: s = pd.Series([1], index=pd.Index(["a"], name="idx"),name='foo')

In [13]: s
Out[13]: 
idx
a    1
Name: foo, dtype: int64

In [14]: s.to_string(name=True,header=True,length=True)
Out[14]: u'idx\na    1\nName: foo, Length: 1'

@jreback jreback closed this as completed Apr 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants