I just want a SIMPLE bar chart

I have StreamLit working fine with some simple things like st.write and even st.table.

I have a CSV file with two columns, “Date” and “Profit/Loss”

Date,Profit/Loss
2022-01-14,-500.00
df =  pd.read_csv('profitloss.csv')

chart_data = pd.DataFrame(df)

st.bar_chart(chart_data)

this code just gives me this error:

**StreamlitAPIException** : ("Expected bytes, got a 'float' object", 'Conversion failed for column value with type object')

What am I doing wrong?

Hi @TheBigDuck

I suggest you replace the above code with the following code:

Also suggest you take a look at other visualization libraries: Altair, etc.

Cheers :slight_smile:

1 Like

Works like a champ!
Thanks!

Hi,

I am experiencing the same problem while using filter_dataframe. When I include float values in the dataframe I get: StreamlitAPIException: (“Expected bytes, got a ‘float’ object”, ‘Conversion failed for column XXX with type object’). I can convert the floats to strings either in config by adding

[global]

dataFrameSerialization = “legacy”

or in the code directly with

df=df.astype(str)

but this defeats the purpose of the filter – I cannot use any slider on my float values.

Is there any workaround?

Please check the type of your pandas columns with dtypes and set the type. If this doesn’t work, it will help if you include some reproducible code for someone to go through and comment.

Cheers

Hi Shawn,
Of course - the column’s dtype was object, all sorted with df[“column_name”] = df[‘column_name’].astype(float)
Thanks a lot.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.