BUG: Index Name is not displayed with header=False in to_csv
- [ ] xref #24546
- [ ] tests added / passed
- [ ] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=h1) Report
> Merging [#24840](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/aa05e542bc47140123157c5854cac498c3541a8c?src=pr&el=desc) will **decrease** coverage by `49.47%`.
> The diff coverage is `50%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24840/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=tree)

```diff
@@             Coverage Diff             @@
##           master   #24840       +/-   ##
===========================================
- Coverage   92.38%   42.91%   -49.48%     
===========================================
  Files         166      166               
  Lines       52382    52390        +8     
===========================================
- Hits        48395    22482    -25913     
- Misses       3987    29908    +25921
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `?` | |
| #single | `42.91% <50%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/csvs.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvY3N2cy5weQ==) | `68.36% <50%> (-29.87%)` | :arrow_down: |
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/core/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY2F0ZWdvcmljYWwucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/sas/sas\_constants.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfY29uc3RhbnRzLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/plotting.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvcGxvdHRpbmcucHk=) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/tseries/converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL3RzZXJpZXMvY29udmVydGVyLnB5) | `0% <0%> (-100%)` | :arrow_down: |
| [pandas/io/formats/html.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvaHRtbC5weQ==) | `0% <0%> (-99.35%)` | :arrow_down: |
| [pandas/core/groupby/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ3JvdXBieS9jYXRlZ29yaWNhbC5weQ==) | `0% <0%> (-95.46%)` | :arrow_down: |
| [pandas/io/sas/sas7bdat.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXM3YmRhdC5weQ==) | `0% <0%> (-91.17%)` | :arrow_down: |
| [pandas/io/sas/sas\_xport.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3Nhcy9zYXNfeHBvcnQucHk=) | `0% <0%> (-90.15%)` | :arrow_down: |
| ... and [124 more](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=footer). Last update [aa05e54...3941906](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
 # [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=h1) Report
> Merging [#24840](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/0f5a7e3a6edace63fcb342a1a0187856aee24b93?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/24840/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #24840      +/-   ##
==========================================
+ Coverage   91.47%   91.47%   +<.01%     
==========================================
  Files         172      173       +1     
  Lines       52870    52882      +12     
==========================================
+ Hits        48362    48376      +14     
+ Misses       4508     4506       -2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.04% <100%> (ø)` | :arrow_up: |
| #single | `41.82% <46.87%> (ø)` | :arrow_up: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `93.52% <ø> (ø)` | :arrow_up: |
| [pandas/io/formats/csvs.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvY3N2cy5weQ==) | `98.36% <100%> (+0.13%)` | :arrow_up: |
| [pandas/io/pytables.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL3B5dGFibGVzLnB5) | `90.19% <0%> (-0.01%)` | :arrow_down: |
| [pandas/io/formats/format.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvZm9ybWF0LnB5) | `97.99% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/interval.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9pbnRlcnZhbC5weQ==) | `95.25% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `95.62% <0%> (ø)` | :arrow_up: |
| [pandas/plotting/\_core.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb3JlLnB5) | `83.65% <0%> (ø)` | :arrow_up: |
| [pandas/io/formats/printing.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvcHJpbnRpbmcucHk=) | `85.34% <0%> (ø)` | :arrow_up: |
| [pandas/core/api.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXBpLnB5) | `100% <0%> (ø)` | :arrow_up: |
| [pandas/core/computation/expressions.py](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvY29tcHV0YXRpb24vZXhwcmVzc2lvbnMucHk=) | `93.27% <0%> (ø)` | :arrow_up: |
| ... and [15 more](https://codecov.io/gh/pandas-dev/pandas/pull/24840/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=footer). Last update [0f5a7e3...3dc0027](https://codecov.io/gh/pandas-dev/pandas/pull/24840?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
 @simonjayhawkins if you'd have a look oh... yeah... output will look different after `to_csv`... need to fix other pytest errors in `read_csv` and maybe `read_csv` function as well... will look into it... thanks for the quick feedback! @charlesdong1991 can you change closes #24546 to xref #24546, other output formatting methods need to be checked before the issue is closed. thanks. `to_csv` is using `CSVFormatter` and does not have an `index_names` parameter like the `DataFrameFormatter` class. is it possible to retain the existing behavior of displaying the index without the index names without a change to the api?  > to_csv is using CSVFormatter and does not have an index_names parameter like the DataFrameFormatter class. is it possible to retain the existing behavior of displaying the index without the index names without a change to the api?

@simonjayhawkins : I'm personally not too concerned if we have to add this parameter to the class.  It's not very visible (if at all) from a general `pandas` API perspective. > oh... yeah... output will look different after to_csv... need to fix other pytest errors in read_csv and maybe read_csv function as well... will look into it... thanks for the quick feedback!

@charlesdong1991 : I strongly suspect that you will not have to modify anything in `read_csv` at this point.  If there are round-trip issues that you observe, let's tackle in a separate PR. > I'm personally not too concerned if we have to add this parameter to the class. It's not very visible (if at all) from a general pandas API perspective

@gfyoung if a parameter is added to `CSVFormatter` it would also need to be added to `to_csv`?

 @simonjayhawkins : Eventually, we should, but for now, we can keep the parameter internal (so as to fix the bug) to `CSVFormatter`.  Changing the API wouldn't be ideal since we are in the middle of an RC cycle, unless we want to delay this until the next major release (or *maybe* next minor one).. 

However, I see no reason to not patch the bug now and then expose `index_names` later. Hello @charlesdong1991! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:









There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2019-03-24 22:25:00 UTC Thanks a lot for all of your reviews! I think this time all should work! 
I changed the design a bit so in this PR:
1. The default is still None, and if index_label is not explicitly called, then index_label is set to False by default if either header or index is False; otherwise, index_label is True by default.
2. If index_label is explicitly called, then index_label will be given following the caller.

Benefits:
1. Fix the bug.
2. Adding flexibility and separating col names and index names correctly.
3. Maintain the backward compatibility and no need to change API for now.

I am looking forward to your feedbacks! @jreback @simonjayhawkins @gfyoung  @charlesdong1991 can you merge master? Thanks @WillAyd , i just merged to master. I pushed some changes based on your nice reviews, @WillAyd looks like there was a connection issue during checking, i will re-push it along with fixes of your potential follow-up change requests :) @charlesdong1991 can you check failures, merge master and address comments?

FYI if you merge master you shouldn't need a force push, which is preferable for maintaining GH comment history Hi, @WillAyd last time it was failed because of master failure, and I just merged the master, and see if the tests can be passed. @charlesdong1991 can you merge master and address comments? @charlesdong1991 can you merge master and address comments? Closing as stale but ping if you'd like to pick this back up!