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

Column headers out of alignment in 10 MInutes tutorial #26955

Open
vlbrown opened this issue Jun 20, 2019 · 3 comments
Open

Column headers out of alignment in 10 MInutes tutorial #26955

vlbrown opened this issue Jun 20, 2019 · 3 comments
Labels
Docs Output-Formatting __repr__ of pandas objects, to_string

Comments

@vlbrown
Copy link

vlbrown commented Jun 20, 2019

Beginning at line In [93]: in getting_started/10min.html, the column headers of the output data frames go out of alignment.

Is this meant to have a semantic meaning that is not addressed by the tutorial commentary?

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
                                         'foo', 'bar', 'foo', 'foo'],
                                   'B': ['one', 'one', 'two', 'three',
                                          'two', 'two', 'one', 'three'],
                                   'C': np.random.randn(8),
                                   'D': np.random.randn(8)})
df.groupby('A').sum()

Problem description

Output column headers do not line up as expected

            C        D
A                     
bar -2.802588  2.42611
foo  3.146492 -0.63958

Expected Output

A         C         D   
bar -2.802588  2.42611
foo  3.146492 -0.63958

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.3.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.24.2
pytest: 4.3.1
pip: 19.0.3
setuptools: 40.8.0
Cython: 0.29.6
numpy: 1.16.2
scipy: 1.2.1
pyarrow: None
xarray: None
IPython: 7.4.0
sphinx: 1.8.5
patsy: 0.5.1
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: 1.2.1
tables: 3.5.1
numexpr: 2.6.9
feather: None
matplotlib: 3.0.3
openpyxl: 2.6.1
xlrd: 1.2.0
xlwt: 1.3.0
xlsxwriter: 1.1.5
lxml.etree: 4.3.2
bs4: 4.7.1
html5lib: 1.0.1
sqlalchemy: 1.3.1
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.7.0
gcsfs: None

@TomAugspurger
Copy link
Contributor

I think that's deliberate. When you groupie 'A', it's moved to the index. Check df.groupby("A").sum().columns and df.groupby("A").sum().index.name.

I wonder if we should note that after doing the .sum(). Something like

"The unique values in the A column now form the index."

@vlbrown
Copy link
Author

vlbrown commented Jun 20, 2019 via email

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Jun 20, 2019 via email

@mroeschke mroeschke added the Output-Formatting __repr__ of pandas objects, to_string label Jul 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

4 participants