question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BUG: df.to_markdown() with empty frame incorrect output

See original GitHub issue

Code Sample, a copy-pastable example if possible

import pandas as pd

df = pd.DataFrame({'id': [], 'first_name': [], 'last_name': []}).set_index('id')
print(df.to_markdown())
| id   | first_name   | last_name   |
||

Problem description

The markdown output of empty DataFrames does not seem right to me (see Expected Output).

Expected Output

| id   | first_name   | last_name   |
|-----:|-------------:|------------:|

Render difference

Current

| id | first_name | last_name | ||

Expected
id first_name last_name

Output of pd.show_versions()

INSTALLED VERSIONS

commit : None python : 3.7.4.final.0 python-bits : 64 OS : Windows OS-release : 10 machine : AMD64 processor : Intel64 Family 6 Model 85 Stepping 4, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : None.None

pandas : 1.0.1 numpy : 1.18.1 pytz : 2019.3 dateutil : 2.8.0 pip : 19.2.3 setuptools : 41.4.0 Cython : 0.29.13 pytest : 5.2.1 hypothesis : None sphinx : 2.2.0 blosc : None feather : None xlsxwriter : 1.2.1 lxml.etree : 4.4.1 html5lib : 1.0.1 pymysql : None psycopg2 : 2.8.4 (dt dec pq3 ext lo64) jinja2 : 2.10.3 IPython : 7.8.0 pandas_datareader: None bs4 : 4.8.0 bottleneck : 1.2.1 fastparquet : None gcsfs : None lxml.etree : 4.4.1 matplotlib : 3.1.1 numexpr : 2.7.0 odfpy : None openpyxl : 3.0.0 pandas_gbq : None pyarrow : None pytables : None pytest : 5.2.1 pyxlsb : None s3fs : None scipy : 1.3.1 sqlalchemy : 1.3.12 tables : 3.5.2 tabulate : 0.8.6 xarray : None xlrd : 1.2.0 xlwt : 1.3.0 xlsxwriter : 1.2.1 numba : 0.45.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
MarcoGorellicommented, Sep 2, 2020

@MarcoGorelli any chance this has resolved itself since Feb?

Yes, that seems to be the case!

In [1]: import pandas as pd 
   ...:  
   ...: df = pd.DataFrame({'id': [], 'first_name': [], 'last_name': []}).set_ind
   ...: ex('id') 
   ...: print(df.to_markdown())                                                 
| id   | first_name   | last_name   |
|------|--------------|-------------|

I’ll look into this to figure out when/how it was fixed

1reaction
alimcmaster1commented, Feb 7, 2020

I’ve asked @astanin

Read more comments on GitHub >

github_iconTop Results From Across the Web

R markdown creates an empty data frame while executed ...
Hi, I have a strange issue. One my code chunks subsets a data frame based on the names of list elements. When I...
Read more >
r - Markdown - return text instead of empty table if no rows are ...
I use the following to select the rows missing values from a dataframe and displaying them as a table in my output.
Read more >
15 Common Problems with rmarkdown (and some solutions)
This error message is pretty good, I needed to add a comma after my chunk name. So, go from: ```{r read-gapminder include =...
Read more >
pandas.DataFrame.to_markdown
Print DataFrame in Markdown-friendly format. New in version 1.0.0. Parameters. bufstr, Path or StringIO-like, optional, default None. Buffer to write to.
Read more >
Introduction to summarytools
dfSummary(), Data Frame Summaries featuring type-specific ... Using report.nas = FALSE makes the output table smaller by one row and two ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found