# Wide format CSV with Plotly Express

**URL:** <https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322>\
**Category:** 📊 Plotly Python\
**Created:** [April 24, 2021, 5:15pm UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322 "2021-04-24T17:15:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgomes\_eu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jgomes_eu/32/14895_2.png) [@jgomes\_eu](https://community.plotly.com/u/jgomes_eu)\
**Post date:** [April 24, 2021, 5:15pm UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/1 "2021-04-24T17:15:45Z")

</div>

Hi everyone  
I have a [wide dataset](https://drive.google.com/file/d/1gKI2ZlgXcE4FA04Do8W5GU9K5XIbkDXU/view?usp=sharing) with COVID-19 data.  
I have the following code in Python:

```auto
# Import Libraries

import pandas as pd 
import plotly.express as px 

# Read CSV file 

df = pd.read_csv("covid19pt_data.csv")

# Plot

fig = px.bar(df)

fig.show()

```

After running it I get the following error message:

**ValueError: Plotly Express cannot process wide-form data with columns of different type**

If I change my code to

```auto
fig = px.bar(df, x='data',y='novos_casos_t')

fig.show()

```

the code works, showing me a bar graph for that column. The same for any other column.

However, after reading **[this post](https://plotly.com/python/wide-form/)** I was under the impression that plotly now supports wide format frames so I don’t understand what I’m clearly doing wrong.

My experience level is close to zero and any help in making me understand what I’m doing wrong is much appreciated.

---

<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:** [April 24, 2021, 10:32pm UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/2 "2021-04-24T22:32:43Z")

</div>

The error message is basically pointing you to the problem… your `df` has multiple columns, and they’re not all of the same type (some are strings, some are numbers, most likely) and Plotly Express doesn’t know what to do with that: you can’t make a bar chart of a mix of strings and numbers 🙂

---

<div class="post-metadata">

**Author:** ![jgomes\_eu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jgomes_eu/32/14895_2.png) [@jgomes\_eu](https://community.plotly.com/u/jgomes_eu)\
**Post date:** [April 25, 2021, 3:42pm UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/3 "2021-04-25T15:42:19Z")

</div>

Hi Nicholas, but all my columns, as you can see in the sample dataset, are numbers. Is this happening because of the headers?

---

<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:** [April 25, 2021, 4:19pm UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/4 "2021-04-25T16:19:18Z")

</div>

Your “data” column doesn’t contain numbers, no 🙂

If you add a line like `df = df.set_index("data")` above your PX call things should work better, because in that case all your remaining columns will be numerical and PX will automatically use your index for the X axis.

---

<div class="post-metadata">

**Author:** ![jgomes\_eu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jgomes_eu/32/14895_2.png) [@jgomes\_eu](https://community.plotly.com/u/jgomes_eu)\
**Post date:** [April 26, 2021, 10:48am UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/5 "2021-04-26T10:48:30Z")

</div>

True, thank you for for your time, @nicolaskruchten

---

<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:** [April 26, 2021, 11:35am UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/6 "2021-04-26T11:35:34Z")

</div>

Sorry the error message wasn’t clearer! Maybe it should list the first two differing-type columns.

---

<div class="post-metadata">

**Author:** ![jgomes\_eu](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jgomes_eu/32/14895_2.png) [@jgomes\_eu](https://community.plotly.com/u/jgomes_eu)\
**Post date:** [April 26, 2021, 12:19pm UTC](https://community.plotly.com/t/wide-format-csv-with-plotly-express/52322/7 "2021-04-26T12:19:44Z")

</div>

That would help, particularly to those - like me - that are new to this.  
My assumption was that plotly would assume that the first column would be the x axis by default, and that the other columns would be the different y axis values and the first row would be the label for those values.  
by using `df = df.set_index('data')` I was able to make it work, even if now I have a total novel problem, that I’m trying to figure out. If I can’t I will probably open a new thread.  
Once more thank you for time and patience.
