python152
python152

Reputation: 1951

Altair hangs with this chart?

I have a simple csv with the following contents:

Pattern, Mode, Bandwidth
Random, Read, 23.988
Random, Write, 30.628
Seq, Read, 38.000
Seq, Write, 33.785

I want to produce a similar grouped bar chart as this one:

import altair as alt
import pandas as pd
df = pd.read_csv("simple.csv")
alt.Chart(df).mark_bar().encode(
    x='Bandwidth:Q',
    y='Mode:N',
    row='Pattern:N'
)

Just hangs altair (I have to kill the session of jupyter notebook to get out of it). That said, if I manually put in the data: pd.DataFrame([ ], [], columns = []. The same drawing command seems work, partially.

Upvotes: 1

Views: 81

Answers (2)

jakevdp
jakevdp

Reputation: 86330

It looks like you have spaces in your CSV file, so the column names are not 'Mode' and 'Bandwidth', but rather ' Mode' and ' Bandwidth' (with leading spaces).

The best fix would be to remove spaces from your CSV file. If that is not possible, then in pandas, you can pass the skipinitialspace=True argument to pd.read_csv to strip these spaces when reading the data into a dataframe.

Upvotes: 1

python152
python152

Reputation: 1951

never mind, it appears I didn't pass in skipinitialspace=True when I read CSV file, and it messed up the column names.

Upvotes: 0

Related Questions