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

- [x] closes #31771
- [x] tests added / passed
- [x] passes `black pandas`
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] added test_empty_frame for test_to_markdown.py (#31771)
- [x] Required tabulate >= 0.8.7


Labels:
name: IO Data
description: IO issues that don't fit into a more specific label
name: Stale

Comments:
/azp run
<samp>
Azure Pipelines successfully started running 1 pipeline(s).<br>

</samp>
Can you add a note about the increase dependency in the 1.2 what’s new? 
> Can you add a note about the increase dependency in the 1.2 what’s new?

Just added.
You will also need to update this reference here:

https://github.com/pandas-dev/pandas/blob/229722e6a24b9658a27fc06b617701ad02aaa435/pandas/compat/_optional.py#L28
> You will also need to update this reference here:
> 
> https://github.com/pandas-dev/pandas/blob/229722e6a24b9658a27fc06b617701ad02aaa435/pandas/compat/_optional.py#L28

Updated
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.
The CI failures on Python 3.8 look related:
```
2020-12-03T03:15:02.4153573Z pandas/compat/_optional.py:126: ImportError
2020-12-03T03:15:02.4153907Z _____________________________ test_other_tablefmt ______________________________
2020-12-03T03:15:02.4154452Z [gw1] linux -- Python 3.8.5 /home/vsts/miniconda3/envs/pandas-dev/bin/python
2020-12-03T03:15:02.4154736Z 
2020-12-03T03:15:02.4154989Z     def test_other_tablefmt():
2020-12-03T03:15:02.4155228Z         buf = StringIO()
2020-12-03T03:15:02.4155482Z         df = pd.DataFrame([1, 2, 3])
2020-12-03T03:15:02.4155771Z >       df.to_markdown(buf=buf, tablefmt="jira")
2020-12-03T03:15:02.4155979Z 
2020-12-03T03:15:02.4156225Z pandas/tests/io/formats/test_to_markdown.py:35: 
2020-12-03T03:15:02.4156545Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-12-03T03:15:02.4156876Z pandas/core/frame.py:2342: in to_markdown
2020-12-03T03:15:02.4157155Z     tabulate = import_optional_dependency("tabulate")
2020-12-03T03:15:02.4157471Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-12-03T03:15:02.4157737Z 
2020-12-03T03:15:02.4158184Z name = 'tabulate', extra = '', raise_on_missing = True, on_version = 'raise'
2020-12-03T03:15:02.4158489Z 
2020-12-03T03:15:02.4158709Z     def import_optional_dependency(
2020-12-03T03:15:02.4159195Z         name: str, extra: str = "", raise_on_missing: bool = True, on_version: str = "raise"
2020-12-03T03:15:02.4159540Z     ):
2020-12-03T03:15:02.4159902Z         """
2020-12-03T03:15:02.4160163Z         Import an optional dependency.
2020-12-03T03:15:02.4160390Z     
2020-12-03T03:15:02.4160653Z         By default, if a dependency is missing an ImportError with a nice
2020-12-03T03:15:02.4161023Z         message will be raised. If a dependency is present, but too old,
2020-12-03T03:15:02.4161305Z         we raise.
2020-12-03T03:15:02.4161525Z     
2020-12-03T03:15:02.4161720Z         Parameters
2020-12-03T03:15:02.4162130Z         ----------
2020-12-03T03:15:02.4162403Z         name : str
2020-12-03T03:15:02.4162889Z             The module name. This should be top-level only, so that the
2020-12-03T03:15:02.4163522Z             version may be checked.
2020-12-03T03:15:02.4163773Z         extra : str
2020-12-03T03:15:02.4164085Z             Additional text to include in the ImportError message.
2020-12-03T03:15:02.4164398Z         raise_on_missing : bool, default True
2020-12-03T03:15:02.4164723Z             Whether to raise if the optional dependency is not found.
2020-12-03T03:15:02.4165055Z             When False and the module is not present, None is returned.
2020-12-03T03:15:02.4165571Z         on_version : str {'raise', 'warn'}
2020-12-03T03:15:02.4166089Z             What to do when a dependency's version is too old.
2020-12-03T03:15:02.4166379Z     
2020-12-03T03:15:02.4166637Z             * raise : Raise an ImportError
2020-12-03T03:15:02.4166944Z             * warn : Warn that the version is too old. Returns None
2020-12-03T03:15:02.4167302Z             * ignore: Return the module, even if the version is too old.
2020-12-03T03:15:02.4167830Z               It's expected that users validate the version locally when
2020-12-03T03:15:02.4168221Z               using ``on_version="ignore"`` (see. ``io/html.py``)
2020-12-03T03:15:02.4168480Z     
2020-12-03T03:15:02.4168665Z         Returns
2020-12-03T03:15:02.4169032Z         -------
2020-12-03T03:15:02.4169317Z         maybe_module : Optional[ModuleType]
2020-12-03T03:15:02.4169657Z             The imported module, when found and the version is correct.
2020-12-03T03:15:02.4170004Z             None is returned when the package is not found and `raise_on_missing`
2020-12-03T03:15:02.4170565Z             is False, or when the package's version is too old and `on_version`
2020-12-03T03:15:02.4171046Z             is ``'warn'``.
2020-12-03T03:15:02.4171316Z         """
2020-12-03T03:15:02.4171512Z     
2020-12-03T03:15:02.4171734Z         package_name = INSTALL_MAPPING.get(name)
2020-12-03T03:15:02.4172059Z         install_name = package_name if package_name is not None else name
2020-12-03T03:15:02.4172335Z     
2020-12-03T03:15:02.4172545Z         msg = (
2020-12-03T03:15:02.4172993Z             f"Missing optional dependency '{install_name}'. {extra} "
2020-12-03T03:15:02.4173530Z             f"Use pip or conda to install {install_name}."
2020-12-03T03:15:02.4173831Z         )
2020-12-03T03:15:02.4174037Z         try:
2020-12-03T03:15:02.4174305Z             module = importlib.import_module(name)
2020-12-03T03:15:02.4174587Z         except ImportError:
2020-12-03T03:15:02.4174873Z             if raise_on_missing:
2020-12-03T03:15:02.4175157Z                 raise ImportError(msg) from None
2020-12-03T03:15:02.4175609Z             else:
2020-12-03T03:15:02.4176051Z                 return None
2020-12-03T03:15:02.4176282Z     
2020-12-03T03:15:02.4176544Z         minimum_version = VERSIONS.get(name)
2020-12-03T03:15:02.4176837Z         if minimum_version:
2020-12-03T03:15:02.4177116Z             version = _get_version(module)
2020-12-03T03:15:02.4177499Z             if distutils.version.LooseVersion(version) < minimum_version:
2020-12-03T03:15:02.4177891Z                 assert on_version in {"warn", "raise", "ignore"}
2020-12-03T03:15:02.4178374Z                 msg = (
2020-12-03T03:15:02.4179083Z                     f"Pandas requires version '{minimum_version}' or newer of '{name}' "
2020-12-03T03:15:02.4179949Z                     f"(version '{version}' currently installed)."
2020-12-03T03:15:02.4180262Z                 )
2020-12-03T03:15:02.4180536Z                 if on_version == "warn":
2020-12-03T03:15:02.4180823Z                     warnings.warn(msg, UserWarning)
2020-12-03T03:15:02.4181086Z                     return None
2020-12-03T03:15:02.4181481Z                 elif on_version == "raise":
2020-12-03T03:15:02.4181786Z >                   raise ImportError(msg)
2020-12-03T03:15:02.4182413Z E                   ImportError: Pandas requires version '0.8.7' or newer of 'tabulate' (version '0.8.3' currently installed).
2020-12-03T03:15:02.4182768Z 
2020-12-03T03:15:02.4183024Z pandas/compat/_optional.py:126: ImportError
2020-12-03T03:15:02.4183444Z ______________________________ test_other_headers ______________________________
2020-12-03T03:15:02.4184003Z [gw1] linux -- Python 3.8.5 /home/vsts/miniconda3/envs/pandas-dev/bin/python
2020-12-03T03:15:02.4184315Z 
2020-12-03T03:15:02.4184537Z     def test_other_headers():
2020-12-03T03:15:02.4184789Z         buf = StringIO()
2020-12-03T03:15:02.4185026Z         df = pd.DataFrame([1, 2, 3])
2020-12-03T03:15:02.4185294Z >       df.to_markdown(buf=buf, headers=["foo", "bar"])
2020-12-03T03:15:02.4185524Z 
2020-12-03T03:15:02.4185754Z pandas/tests/io/formats/test_to_markdown.py:43: 
2020-12-03T03:15:02.4186199Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-12-03T03:15:02.4186572Z pandas/core/frame.py:2342: in to_markdown
2020-12-03T03:15:02.4186852Z     tabulate = import_optional_dependency("tabulate")
2020-12-03T03:15:02.4187191Z _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
2020-12-03T03:15:02.4187625Z 
2020-12-03T03:15:02.4188133Z name = 'tabulate', extra = '', raise_on_missing = True, on_version = 'raise'
2020-12-03T03:15:02.4188436Z 
2020-12-03T03:15:02.4188666Z     def import_optional_dependency(
2020-12-03T03:15:02.4189052Z         name: str, extra: str = "", raise_on_missing: bool = True, on_version: str = "raise"
2020-12-03T03:15:02.4189560Z     ):
2020-12-03T03:15:02.4189784Z         """
2020-12-03T03:15:02.4190024Z         Import an optional dependency.
2020-12-03T03:15:02.4190299Z     
2020-12-03T03:15:02.4190575Z         By default, if a dependency is missing an ImportError with a nice
2020-12-03T03:15:02.4191114Z         message will be raised. If a dependency is present, but too old,
2020-12-03T03:15:02.4191416Z         we raise.
2020-12-03T03:15:02.4191617Z     
2020-12-03T03:15:02.4191832Z         Parameters
2020-12-03T03:15:02.4192443Z         ----------
2020-12-03T03:15:02.4192731Z         name : str
2020-12-03T03:15:02.4193246Z             The module name. This should be top-level only, so that the
2020-12-03T03:15:02.4193611Z             version may be checked.
2020-12-03T03:15:02.4193898Z         extra : str
2020-12-03T03:15:02.4194188Z             Additional text to include in the ImportError message.
2020-12-03T03:15:02.4194542Z         raise_on_missing : bool, default True
2020-12-03T03:15:02.4194878Z             Whether to raise if the optional dependency is not found.
2020-12-03T03:15:02.4195255Z             When False and the module is not present, None is returned.
2020-12-03T03:15:02.4195763Z         on_version : str {'raise', 'warn'}
2020-12-03T03:15:02.4196307Z             What to do when a dependency's version is too old.
2020-12-03T03:15:02.4196638Z     
2020-12-03T03:15:02.4196898Z             * raise : Raise an ImportError
2020-12-03T03:15:02.4197246Z             * warn : Warn that the version is too old. Returns None
2020-12-03T03:15:02.4197619Z             * ignore: Return the module, even if the version is too old.
2020-12-03T03:15:02.4198378Z               It's expected that users validate the version locally when
2020-12-03T03:15:02.4198947Z               using ``on_version="ignore"`` (see. ``io/html.py``)
2020-12-03T03:15:02.4199243Z     
2020-12-03T03:15:02.4199469Z         Returns
2020-12-03T03:15:02.4200150Z         -------
2020-12-03T03:15:02.4200479Z         maybe_module : Optional[ModuleType]
2020-12-03T03:15:02.4200812Z             The imported module, when found and the version is correct.
2020-12-03T03:15:02.4201193Z             None is returned when the package is not found and `raise_on_missing`
2020-12-03T03:15:02.4201965Z             is False, or when the package's version is too old and `on_version`
2020-12-03T03:15:02.4203309Z             is ``'warn'``.
2020-12-03T03:15:02.4203605Z         """
2020-12-03T03:15:02.4203808Z     
2020-12-03T03:15:02.4204065Z         package_name = INSTALL_MAPPING.get(name)
2020-12-03T03:15:02.4204386Z         install_name = package_name if package_name is not None else name
2020-12-03T03:15:02.4204674Z     
2020-12-03T03:15:02.4204872Z         msg = (
2020-12-03T03:15:02.4205648Z             f"Missing optional dependency '{install_name}'. {extra} "
2020-12-03T03:15:02.4206047Z             f"Use pip or conda to install {install_name}."
2020-12-03T03:15:02.4206303Z         )
2020-12-03T03:15:02.4206519Z         try:
2020-12-03T03:15:02.4206757Z             module = importlib.import_module(name)
2020-12-03T03:15:02.4207037Z         except ImportError:
2020-12-03T03:15:02.4207299Z             if raise_on_missing:
2020-12-03T03:15:02.4207568Z                 raise ImportError(msg) from None
2020-12-03T03:15:02.4207832Z             else:
2020-12-03T03:15:02.4208053Z                 return None
2020-12-03T03:15:02.4208269Z     
2020-12-03T03:15:02.4208485Z         minimum_version = VERSIONS.get(name)
2020-12-03T03:15:02.4208756Z         if minimum_version:
2020-12-03T03:15:02.4209010Z             version = _get_version(module)
2020-12-03T03:15:02.4209362Z             if distutils.version.LooseVersion(version) < minimum_version:
2020-12-03T03:15:02.4209739Z                 assert on_version in {"warn", "raise", "ignore"}
2020-12-03T03:15:02.4210004Z                 msg = (
2020-12-03T03:15:02.4210520Z                     f"Pandas requires version '{minimum_version}' or newer of '{name}' "
2020-12-03T03:15:02.4211086Z                     f"(version '{version}' currently installed)."
2020-12-03T03:15:02.4211417Z                 )
2020-12-03T03:15:02.4211670Z                 if on_version == "warn":
2020-12-03T03:15:02.4211953Z                     warnings.warn(msg, UserWarning)
2020-12-03T03:15:02.4212230Z                     return None
2020-12-03T03:15:02.4212497Z                 elif on_version == "raise":
2020-12-03T03:15:02.4212794Z >                   raise ImportError(msg)
2020-12-03T03:15:02.4213389Z E                   ImportError: Pandas requires version '0.8.7' or newer of 'tabulate' (version '0.8.3' currently installed).
2020-12-03T03:15:02.4213765Z 
2020-12-03T03:15:02.4213996Z pandas/compat/_optional.py:126: ImportError
```
Might we want to bump the version of `tabulate` in that environment?
Closing in favor of  #38406