# Df.plot(kind='box') with plotly returns error of wide-form data

**URL:** <https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729>\
**Category:** 📊 Plotly Python\
**Created:** [June 7, 2020, 10:48pm UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729 "2020-06-07T22:48:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![set92](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/set92/32/11238_2.png) [@set92](https://community.plotly.com/u/set92)\
**Post date:** [June 7, 2020, 10:48pm UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/1 "2020-06-07T22:48:20Z")

</div>

I was trying to use px to create a boxplot for all the columns in a dataset (890k x 85) since df.plot(kind=‘box’) doesn’t give me interactivity.

The dataset has not been clean, so it has empty columns, ordinal, categorical columns… but is similar as:

| | A | B | C | D | E | F | G | H | I | J | … | K | L | M | N | O | P | Q | R | S | T |
| --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- | --- |
| 0 | NaN | 2.0 | 1 | 2.0 | 3 | 4 | 3 | 5 | 5 | 3 | … | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
| 1 | NaN | 1.0 | 2 | 5.0 | 1 | 5 | 2 | 5 | 4 | 5 | … | 2.0 | 3.0 | 2.0 | 1.0 | 1.0 | 5.0 | 4.0 | 3.0 | 5.0 | 4.0 |
| 2 | NaN | 3.0 | 2 | 3.0 | 1 | 4 | 1 | 2 | 3 | 5 | … | 3.0 | 3.0 | 1.0 | 0.0 | 1.0 | 4.0 | 4.0 | 3.0 | 5.0 | 2.0 |

I was using px.box(df) and returns “ValueError: Plotly Express cannot process wide-form data with columns of different type.”, but I think my data is in a tidy form, so I suppose is an error? I suppose I could fallback to traces but I wanted to know if it was an error that I was doing since it needs a transformation or it was a bug of plotly.

---

<div class="post-metadata">

**Author:** ![nicolaskruchten](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nicolaskruchten/32/7018_2.png) [@nicolaskruchten](https://community.plotly.com/u/nicolaskruchten)\
**Post date:** [June 7, 2020, 11:21pm UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/2 "2020-06-07T23:21:52Z")

</div>

This is intentional: as the error message says, wide-form data is only accepted as is so long as all the columns are the same type, so you must select, say, only the numerical columns, as would make sense for a box plot.

---

<div class="post-metadata">

**Author:** ![nicolaskruchten](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nicolaskruchten/32/7018_2.png) [@nicolaskruchten](https://community.plotly.com/u/nicolaskruchten)\
**Post date:** [June 8, 2020, 2:29am UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/3 "2020-06-08T02:29:59Z")

</div>

Follow-up: I do see that Pandas’ built-in backend does this filtering automatically for `kind="box"` and this is something we can consider baking in to our backend, but at the moment, you’ll have to explicitly provide either a dataframe with only numerical columns, i.e. `df[["A","B","C"]].plot(kind="box")` or a mixed dataframe with a specified list of columns to plot i.e. `df.plot(kind="box", y=["A","B","C"])`

---

<div class="post-metadata">

**Author:** ![set92](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/set92/32/11238_2.png) [@set92](https://community.plotly.com/u/set92)\
**Post date:** [June 8, 2020, 7:57am UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/4 "2020-06-08T07:57:05Z")

</div>

I thought it could be a bug because the data is not in wide-form no? I thought wide form was only when it had 2 axis like the wide\_df here:

 ![](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/ae6ff6fddf5707d028cb951d2fc51306232bd354.png)  
But like they say, You learn something new every day 😃 . So thanks for taking your time to answer and investigate, and all the hard work you do to answer all of us, that most of the time are basic questions.

---

<div class="post-metadata">

**Author:** ![set92](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/set92/32/11238_2.png) [@set92](https://community.plotly.com/u/set92)\
**Post date:** [June 8, 2020, 3:55pm UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/5 "2020-06-08T15:55:39Z")

</div>

I think this is a bug. In pandas I saw what you said, it takes out categorical columns, but it used the rest of columns, mainly float64 and int64.

Instead with plotly if I try to plot the boxplot of A, B it works, if I try to px.box(aux.iloc[:,:3]) it returns again “ValueError: Plotly Express cannot process wide-form data with columns of different type.”. And okay, is true that there are different types, but in pandas works, and here I suppose it should work too since both are numeric types.

I used the data from the first post, being A&B float64, and C int64.

---

<div class="post-metadata">

**Author:** ![nicolaskruchten](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/nicolaskruchten/32/7018_2.png) [@nicolaskruchten](https://community.plotly.com/u/nicolaskruchten)\
**Post date:** [June 27, 2020, 11:44am UTC](https://community.plotly.com/t/df-plot-kind-box-with-plotly-returns-error-of-wide-form-data/40729/6 "2020-06-27T11:44:45Z")

</div>

@set92 thanks for the feedback! as of version 4.8.2, all numeric types are considered “the same type” for the purposes of wide-form processing.
