ENH: DataFrame.pivot accepts a list of values
State: closed

- [x] closes https://github.com/pandas-dev/pandas/issues/17160
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry


Labels:
name: Enhancement
name: Reshaping
description: Concat, Merge/Join, Stack/Unstack, Explode

Comments:
Hello @ibrahimsharaf! Thanks for updating the PR.







Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on March 20, 2018 at 15:31 Hours UTC
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18636?src=pr&el=h1) Report
> Merging [#18636](https://codecov.io/gh/pandas-dev/pandas/pull/18636?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/a7646638d06f1ce98481b88f3505e2b4badf172c?src=pr&el=desc) will **decrease** coverage by `0.03%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #18636      +/-   ##
==========================================
- Coverage   91.59%   91.55%   -0.04%     
==========================================
  Files         155      155              
  Lines       51255    51255              
==========================================
- Hits        46948    46929      -19     
- Misses       4307     4326      +19
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `89.42% <100%> (-0.02%)` | :arrow_down: |
| #single | `40.67% <0%> (-0.11%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18636?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `25% <0%> (-58.34%)` | :arrow_down: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `63.44% <0%> (-1.82%)` | :arrow_down: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.81% <0%> (-0.1%)` | :arrow_down: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `82.01% <0%> (+0.19%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18636?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/18636?src=pr&el=footer). Last update [a764663...5f94728](https://codecov.io/gh/pandas-dev/pandas/pull/18636?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/18636?src=pr&el=h1) Report
> Merging [#18636](https://codecov.io/gh/pandas-dev/pandas/pull/18636?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/01882ba5b4c21b0caf2e6b9279fb01967aa5d650?src=pr&el=desc) will **decrease** coverage by `0.02%`.
> The diff coverage is `100%`.

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

```diff
@@            Coverage Diff             @@
##           master   #18636      +/-   ##
==========================================
- Coverage    91.8%   91.77%   -0.03%     
==========================================
  Files         152      152              
  Lines       49215    49217       +2     
==========================================
- Hits        45181    45171      -10     
- Misses       4034     4046      +12
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.16% <100%> (-0.03%)` | :arrow_down: |
| #single | `41.84% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/18636?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.18% <ø> (ø)` | :arrow_up: |
| [pandas/core/reshape/reshape.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvcmVzaGFwZS9yZXNoYXBlLnB5) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/plotting/\_converter.py](https://codecov.io/gh/pandas-dev/pandas/pull/18636/diff?src=pr&el=tree#diff-cGFuZGFzL3Bsb3R0aW5nL19jb252ZXJ0ZXIucHk=) | `65.07% <0%> (-1.74%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/18636?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/18636?src=pr&el=footer). Last update [01882ba...e293741](https://codecov.io/gh/pandas-dev/pandas/pull/18636?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

@jreback should the [documentation page](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.pivot.html) be modified at this PR? 
> @jreback should the documentation page be modified at this PR?

Yes, you need to update the docstring / tutorial docs in this PR.

Can you show an actual example of what this PR can do? (eg show the result of the df in the test) As the test example result looks a bit strange from a quick look (all the NaNs)
@jreback can you help me find the reason of test failing ([Travis log](https://travis-ci.org/pandas-dev/pandas/jobs/313280839#L2132))? it happens when I pass the values columns as a tuple in those lines ([test](https://github.com/pandas-dev/pandas/pull/18636/files#diff-52cd4a8cbeafc8b5ec9110e1de9d023fR384), [def](https://github.com/pandas-dev/pandas/pull/18636/files#diff-fef81b7e498e469973b2da18d19ff6f3R382))

I tried adding tuple type in this condition ([core/frame.py](https://github.com/pandas-dev/pandas/blob/master/pandas/core/frame.py#L2150)), it passed this test, but failed many others.
The reason of the error is that a tuple `('bar', 'baz')` is seen as a single column name (for a MultiIndex), which is the correct behaviour IMO. So you shouldn't try to interpret a list the same as a tuple.
So what you are saying is that dealing with a tuple of values should be split from the [`is_list_like`](https://github.com/ibrahimsharaf/pandas/blob/539ffdc8e236e5564a187bd2e4e5e6f0f1540be0/pandas/core/reshape/reshape.py#L380) in pivot function?
Hi @jreback, can you give me a hand in here? https://travis-ci.org/pandas-dev/pandas/jobs/325099021#L2255
Updated on top of master, @ibrahimsharaf do you want to check the merge, I'm not sure if I got your changes 100% correct. We'll see if the tests pass.
Hi @jreback, thanks for reviewing. We still have a KeyError exception with the MultiIndex failing test, how do you think it should be fixed?
can u paste what case is failing 
Here: https://travis-ci.org/pandas-dev/pandas/jobs/348034399#L2303
https://github.com/pandas-dev/pandas/issues/19966 for the isssue causing that test to fail.

We can see how hard that is to fix. I'd say just xfail the test for now, rather than trying to work around it.
Shall you guys take a look? @jreback @jorisvandenbossche @TomAugspurger 
lgtm @ibrahimsharaf 

@TomAugspurger @jorisvandenbossche might have some comments
Can you @jreback @jorisvandenbossche restart Travis build?
ping @jorisvandenbossche 
lgtm. @jorisvandenbossche merge when ok.
@ibrahimsharaf Thanks a lot!