dataprofessor / streamlit_freecodecamp

Build 12 Data Apps in Python with Streamlit
577 stars 541 forks source link

Update basketball_app.py #10

Open odagayev opened 2 years ago

odagayev commented 2 years ago

Changing the data type to str in order to avoid the "("Expected bytes, got a 'int' object", 'Conversion failed for column FG% with type object')" error by the st.dataframe on line 45.

This is a new error introduced in streamlit v.85.

Luismbpr commented 9 months ago

Hello. I propose the following minor changes. This is to make sure there are no conflicts regarding strings on the correlation so the heat map is displayed.

  1. Dropping the non-numerical columns (Player, Position and Team) from the re-uploaded DataFrame.
  2. Adding the st.pyplot(f) so the figure shows correctly.

The code would be:

# Heatmap
if st.button('Intercorrelation Heatmap'):
    st.header('Intercorrelation Matrix Heatmap')
    df_selected_team.to_csv('output.csv',index=False)
    df = pd.read_csv('output.csv')
    #Dropping Non-Numerical (string) Columns
    df_selected_htmp = df.drop(columns=['Player', 'Pos', 'Tm'], axis=1)
#    corr = df.corr()
    corr = df_selected_htmp.corr()
    mask = np.zeros_like(corr)
    mask[np.triu_indices_from(mask)] = True
    with sns.axes_style("white"):
        f, ax = plt.subplots(figsize=(7, 5))
        ax = sns.heatmap(corr, mask=mask, vmax=1, square=True)
    st.pyplot(f)